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