This repository was archived by the owner on Aug 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed
Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # ## BEGIN INIT INFO
4+ # Provides: exampledaemon
5+ # Required-Start: $local_fs $remote_fs $network $syslog
6+ # Required-Stop: $local_fs $remote_fs $network $syslog
7+ # Default-Start: 2 3 4 5
8+ # Default-Stop: 0 1 6
9+ # Short-Description: Example
10+ # Description: Example start-stop-daemon - Debian
11+ # ## END INIT INFO
12+
13+ NAME=" rtmbot"
14+ PATH=" /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
15+ APPDIR=" /opt/rtmbot"
16+ APPBIN=" rtmbot.py"
17+ APPARGS=" --config ${APPDIR} /rtmbot.conf"
18+ USER=" ubuntu"
19+ GROUP=" ubuntu"
20+
21+ # Include functions
22+ set -e
23+ . /lib/lsb/init-functions
24+
25+ start () {
26+ printf " Starting '$NAME '... "
27+ start-stop-daemon --start --background --chuid " $USER :$GROUP " --make-pidfile --pidfile /var/run/$NAME .pid --exec " $APPDIR /$APPBIN " -- $APPARGS || true
28+ printf " done\n"
29+ }
30+
31+ # We need this function to ensure the whole process tree will be killed
32+ killtree () {
33+ local _pid=$1
34+ local _sig=${2-TERM}
35+ for _child in $( ps -o pid --no-headers --ppid ${_pid} ) ; do
36+ killtree ${_child} ${_sig}
37+ done
38+ kill -${_sig} ${_pid}
39+ }
40+
41+ stop () {
42+ printf " Stopping '$NAME '... "
43+ [ -z ` cat /var/run/$NAME .pid 2> /dev/null` ] || \
44+ while test -d /proc/$( cat /var/run/$NAME .pid) ; do
45+ killtree $( cat /var/run/$NAME .pid) 15
46+ sleep 0.5
47+ done
48+ [ -z ` cat /var/run/$NAME .pid 2> /dev/null` ] || rm /var/run/$NAME .pid
49+ printf " done\n"
50+ }
51+
52+ status () {
53+ status_of_proc -p /var/run/$NAME .pid " " $NAME && exit 0 || exit $?
54+ }
55+
56+ case " $1 " in
57+ start)
58+ start
59+ ;;
60+ stop)
61+ stop
62+ ;;
63+ restart)
64+ stop
65+ start
66+ ;;
67+ status)
68+ status
69+ ;;
70+ * )
71+ echo " Usage: $NAME {start|stop|restart|status}" >&2
72+ exit 1
73+ ;;
74+ esac
75+
76+ exit 0
You can’t perform that action at this time.
0 commit comments