-
Notifications
You must be signed in to change notification settings - Fork 2
/
initd.sh
executable file
·74 lines (66 loc) · 1.99 KB
/
initd.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
73
74
#!/bin/bash
### BEGIN INIT INFO
# Provides: demo_site
# Required-Start: mysql
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start demo docker daemon engine at boot time
# Description: Enable daemon functions (create docker instances, opening ports, ...)
### END INIT INFO
# Daemon init script 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/>.
NAME=demo_site
RUNDIR=/var/run
PIDFILE=$RUNDIR/demo_server.pid
DAEMON=DAEMON_PATH
DAEMON_ARGS="daemon pidfile $PIDFILE"
case "$1" in
start)
echo -n "Starting $DESC: "
mkdir -p $RUNDIR
touch $PIDFILE
chown root:root $PIDFILE
if start-stop-daemon --start --oknodo --background --pidfile $PIDFILE --chuid root:root --exec $DAEMON -- $DAEMON_ARGS
then
echo "$NAME. Started"
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $NAME: "
if [ -s $PIDFILE ]
then
kill $(pstree -p `cat $PIDFILE` | tr "\n" " " |sed "s/[^0-9]/ /g" |sed "s/\s\s*/ /g")
echo "$NAME. Stopped"
else
echo "Failed to stop daemon, no such pid file, is daemon running?"
fi
rm -f $PIDFILE
;;
restart|reload|force-reload)
$0 stop
sleep 1
$0 start
;;
status)
status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME}
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
exit 1
esac