summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/tox_bootstrap_daemon.sh
diff options
context:
space:
mode:
Diffstat (limited to 'other/bootstrap_daemon/tox_bootstrap_daemon.sh')
-rw-r--r--other/bootstrap_daemon/tox_bootstrap_daemon.sh110
1 files changed, 110 insertions, 0 deletions
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh
new file mode 100644
index 00000000..83d9a119
--- /dev/null
+++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh
@@ -0,0 +1,110 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: tox_bootstrap_daemon
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 server daemon"
15NAME=tox_bootstrap_daemon
16# You may want to change USER if you are using it anywhere else
17USER=tom
18CFG=/home/$USER/.$NAME/conf
19DAEMON=/home/$USER/$NAME
20DAEMON_ARGS="$CFG"
21PIDFILE=/home/$USER/.$NAME/pid
22SCRIPTNAME=/etc/init.d/$NAME
23
24# Exit if the package is not installed
25[ -x "$DAEMON" ] || exit 0
26
27# Read configuration variable file if it is present
28#[ -r /etc/default/$NAME ] && . /etc/default/$NAME
29
30# Load the VERBOSE setting and other rcS variables
31. /lib/init/vars.sh
32
33# Define LSB log_* functions.
34# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
35# and status_of_proc is working.
36. /lib/lsb/init-functions
37
38#
39# Function that starts the daemon/service
40#
41do_start()
42{
43 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
44 || return 1
45 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
46 $DAEMON_ARGS \
47 || return 2
48 sleep 1
49}
50
51#
52# Function that stops the daemon/service
53#
54do_stop()
55{
56 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
57 RETVAL="$?"
58 [ "$RETVAL" = 2 ] && return 2
59
60 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
61 [ "$?" = 2 ] && return 2
62 # Many daemons don't delete their pidfiles when they exit.
63 rm -f $PIDFILE
64 return "$RETVAL"
65}
66
67case "$1" in
68 start)
69 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
70 do_start
71 case "$?" in
72 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
73 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
74 esac
75 ;;
76 stop)
77 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
78 do_stop
79 case "$?" in
80 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
81 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
82 esac
83 ;;
84 status)
85 status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
86 ;;
87
88 restart) #|force-reload)
89 log_daemon_msg "Restarting $DESC" "$NAME"
90 do_stop
91 case "$?" in
92 0|1)
93 do_start
94 case "$?" in
95 0) log_end_msg 0 ;;
96 1) log_end_msg 1 ;; # Old process is still running
97 *) log_end_msg 1 ;; # Failed to start
98 esac
99 ;;
100 *)
101 # Failed to stop
102 log_end_msg 1
103 ;;
104 esac
105 ;;
106 *)
107 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
108 exit 3
109 ;;
110esac