-
Notifications
You must be signed in to change notification settings - Fork 2
/
daemon.sh
executable file
·72 lines (64 loc) · 1.92 KB
/
daemon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Daemon of the docker demo site
# Copyright (C) 2016 Marcos Zuriaga Miguel <wolfi at wolfi.es>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
# Load configuration
source $SCRIPTPATH/daemon_config
# Sets up the autostart features on rc.d and init.d to launch the daemon on boot
function install_autostart() {
# Copy the script to the init scripts
cp $SCRIPTPATH/initd.sh /etc/init.d/demo_site
# Insert absolute path to this file
sed -i "s|DAEMON_PATH|$SCRIPT|g" /etc/init.d/demo_site
# Enable rc.d autorun of the daemon
update-rc.d demo_site defaults
update-rc.d demo_site enable
}
# Runs the actual daemon and restarts it in case it fails
function daemon(){
while (true);
do
php $SCRIPTPATH/index.php Daemon >> $LOG_PATH 2>&1
sleep 2
done
}
# Deletes the autostart from rc levels and init script
function remove_autostart() {
rm /etc/init.d/demo_site
update-rc.d demo_site remove
}
case "$1" in
install)
install_autostart
;;
daemon)
case "$2" in
pidfile)
echo $$ > $3
;;
esac
daemon
;;
uninstall)
remove_autostart
;;
*)
echo "usage: daemon.sh install|uninstall|daemon";
echo "This script must be run as root!";
esac