summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/tox-bootstrapd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'other/bootstrap_daemon/tox-bootstrapd.sh')
-rw-r--r--other/bootstrap_daemon/tox-bootstrapd.sh116
1 files changed, 116 insertions, 0 deletions
diff --git a/other/bootstrap_daemon/tox-bootstrapd.sh b/other/bootstrap_daemon/tox-bootstrapd.sh
new file mode 100644
index 00000000..a6c137bd
--- /dev/null
+++ b/other/bootstrap_daemon/tox-bootstrapd.sh
@@ -0,0 +1,116 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: tox-bootstrapd
4# Required-Start: $remote_fs $syslog
5# Required-Stop: $remote_fs $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Starts the Tox DHT bootstrapping server daemon
9# Description: Starts the Tox DHT bootstrapping server daemon
10### END INIT INFO
11
12# PATH should only include /usr/* if it runs after the mountnfs.sh script
13PATH=/sbin:/usr/sbin:/bin:/usr/bin
14DESC="Tox DHT bootstrap daemon"
15NAME=tox-bootstrapd
16DAEMON=/usr/local/bin/$NAME
17CFGFILE=/etc/$NAME.conf
18DAEMON_ARGS="$CFGFILE"
19PIDDIR=/var/run/$NAME
20PIDFILE=$PIDDIR/$NAME.pid
21SCRIPTNAME=/etc/init.d/$NAME
22USER=tox-bootstrapd
23GROUP=tox-bootstrapd
24
25# Exit if the package is not installed
26[ -x "$DAEMON" ] || exit 5
27
28# Load the VERBOSE setting and other rcS variables
29. /lib/init/vars.sh
30
31# Define LSB log_* functions.
32# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
33# and status_of_proc is working.
34. /lib/lsb/init-functions
35
36#
37# Function that starts the daemon/service
38#
39do_start()
40{
41 # Return
42 # 0 if daemon has been started
43 # 1 if daemon was already running
44 # 2 if daemon could not be started
45 if [ ! -d $PIDDIR ]
46 then
47 mkdir $PIDDIR
48 fi
49 chown $USER:$GROUP $PIDDIR
50 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1
51 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS || return 2
52}
53
54#
55# Function that stops the daemon/service
56#
57do_stop()
58{
59 # Return
60 # 0 if daemon has been stopped
61 # 1 if daemon was already stopped
62 # 2 if daemon could not be stopped
63 # other if a failure occurred
64 start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE --name $NAME --chuid $USER
65 RETVAL="$?"
66 [ "$RETVAL" = 2 ] && return 2
67 # Many daemons don't delete their pidfiles when they exit.
68 rm -f $PIDFILE
69 return "$RETVAL"
70}
71
72case "$1" in
73 start)
74 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
75 do_start
76 case "$?" in
77 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
78 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
79 esac
80 ;;
81 stop)
82 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
83 do_stop
84 case "$?" in
85 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
86 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
87 esac
88 ;;
89 status)
90 status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
91 ;;
92
93 restart)
94 log_daemon_msg "Restarting $DESC" "$NAME"
95 do_stop
96 case "$?" in
97 0|1)
98 do_start
99 case "$?" in
100 0) log_end_msg 0 ;;
101 1) log_end_msg 1 ;; # Old process is still running
102 *) log_end_msg 1 ;; # Failed to start
103 esac
104 ;;
105 *)
106 # Failed to stop
107 log_end_msg 1
108 ;;
109 esac
110 ;;
111 *)
112 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
113 exit 3
114 ;;
115esac
116exit 0 \ No newline at end of file