diff options
Diffstat (limited to 'other/bootstrap_serverdaemon/initscript.sh')
-rw-r--r-- | other/bootstrap_serverdaemon/initscript.sh | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/other/bootstrap_serverdaemon/initscript.sh b/other/bootstrap_serverdaemon/initscript.sh new file mode 100644 index 00000000..aa4b3e77 --- /dev/null +++ b/other/bootstrap_serverdaemon/initscript.sh | |||
@@ -0,0 +1,109 @@ | |||
1 | #! /bin/sh | ||
2 | ### BEGIN INIT INFO | ||
3 | # Provides: bootstrap_server | ||
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=bootstrap_server | ||
17 | DAEMON=/home/$USER/$NAME | ||
18 | DAEMON_ARGS="" | ||
19 | PIDFILE=/home/$USER/.$NAME.pid | ||
20 | SCRIPTNAME=/etc/init.d/$NAME | ||
21 | |||
22 | # Exit if the package is not installed | ||
23 | [ -x "$DAEMON" ] || exit 0 | ||
24 | |||
25 | # Read configuration variable file if it is present | ||
26 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME | ||
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 | # | ||
39 | do_start() | ||
40 | { | ||
41 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ | ||
42 | || return 1 | ||
43 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ | ||
44 | $DAEMON_ARGS \ | ||
45 | || return 2 | ||
46 | sleep 1 | ||
47 | } | ||
48 | |||
49 | # | ||
50 | # Function that stops the daemon/service | ||
51 | # | ||
52 | do_stop() | ||
53 | { | ||
54 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON | ||
55 | RETVAL="$?" | ||
56 | [ "$RETVAL" = 2 ] && return 2 | ||
57 | |||
58 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON | ||
59 | [ "$?" = 2 ] && return 2 | ||
60 | # Many daemons don't delete their pidfiles when they exit. | ||
61 | rm -f $PIDFILE | ||
62 | return "$RETVAL" | ||
63 | } | ||
64 | |||
65 | case "$1" in | ||
66 | start) | ||
67 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" | ||
68 | do_start | ||
69 | case "$?" in | ||
70 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | ||
71 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | ||
72 | esac | ||
73 | ;; | ||
74 | stop) | ||
75 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | ||
76 | do_stop | ||
77 | case "$?" in | ||
78 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | ||
79 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | ||
80 | esac | ||
81 | ;; | ||
82 | status) | ||
83 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | ||
84 | ;; | ||
85 | |||
86 | restart) #|force-reload) | ||
87 | log_daemon_msg "Restarting $DESC" "$NAME" | ||
88 | do_stop | ||
89 | case "$?" in | ||
90 | 0|1) | ||
91 | do_start | ||
92 | case "$?" in | ||
93 | 0) log_end_msg 0 ;; | ||
94 | 1) log_end_msg 1 ;; # Old process is still running | ||
95 | *) log_end_msg 1 ;; # Failed to start | ||
96 | esac | ||
97 | ;; | ||
98 | *) | ||
99 | # Failed to stop | ||
100 | log_end_msg 1 | ||
101 | ;; | ||
102 | esac | ||
103 | ;; | ||
104 | *) | ||
105 | echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 | ||
106 | exit 3 | ||
107 | ;; | ||
108 | esac | ||
109 | |||