diff options
author | mannol <eniz_vukovic@hotmail.com> | 2014-02-23 23:24:07 +0100 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2014-02-23 23:24:07 +0100 |
commit | cf8a090cdeeb2630730203144001f1357b25ee01 (patch) | |
tree | ac52dcc5d043248cd719004d4eaffde64a65e3d3 /other/bootstrap_daemon/tox_bootstrap_daemon.sh | |
parent | 4888d916d037e371c88d39951f24f6ef4219c7cc (diff) | |
parent | f219fb4ac1bf60eea3117df4aa8615cd07738a69 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'other/bootstrap_daemon/tox_bootstrap_daemon.sh')
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.sh | 110 |
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 | ||
13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
14 | DESC="Tox DHT bootstrap server daemon" | ||
15 | NAME=tox_bootstrap_daemon | ||
16 | # You may want to change USER if you are using it anywhere else | ||
17 | USER=tom | ||
18 | CFG=/home/$USER/.$NAME/conf | ||
19 | DAEMON=/home/$USER/$NAME | ||
20 | DAEMON_ARGS="$CFG" | ||
21 | PIDFILE=/home/$USER/.$NAME/pid | ||
22 | SCRIPTNAME=/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 | # | ||
41 | do_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 | # | ||
54 | do_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 | |||
67 | case "$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 | ;; | ||
110 | esac | ||