tools/init.debian

changeset 744
b8ccc85675a0
parent 575
fd9e4838648f
equal deleted inserted replaced
743:7a4adede7d3f 744:b8ccc85675a0
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: bmsd
4 # Required-Start: $local_fs $remote_fs $network $syslog
5 # Required-Stop: $local_fs $remote_fs $network $syslog
6 # Should-Start: mosquitto
7 # Should-Stop: mosquitto
8 # Default-Start: 2 3 4 5
9 # Default-Stop: 0 1 6
10 # Short-Description: Brewery Management Daemon
11 # Description: This program is the central daemon to collect data
12 # from and control remote devices in a brewery. It is
13 # the production and inventory database.
14 ### END INIT INFO
15
16 # Author: Michiel Broek <mbroek@mbse.eu>
17
18 # Do NOT "set -e"
19
20 # PATH should only include /usr/* if it runs after the mountnfs.sh script
21 PATH=/sbin:/usr/sbin:/bin:/usr/bin
22 DESC="Brewery Management Daemon"
23 NAME=bmsd
24 DAEMON=/var/lib/bms/bin/$NAME
25 #DAEMON_ARGS="--options args"
26 PIDFILE=/var/lib/bms/.bms/run/$NAME.pid
27 SCRIPTNAME=/etc/init.d/$NAME
28
29 # Exit if the package is not installed
30 [ -x "$DAEMON" ] || exit 0
31
32 # Read configuration variable file if it is present
33 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
34
35 # Load the VERBOSE setting and other rcS variables
36 . /lib/init/vars.sh
37
38 # Define LSB log_* functions.
39 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
40 # and status_of_proc is working.
41 . /lib/lsb/init-functions
42
43 #
44 # Function that starts the daemon/service
45 #
46 do_start()
47 {
48 # Return
49 # 0 if daemon has been started
50 # 1 if daemon was already running
51 # other if daemon could not be started or a failure occured
52 start-stop-daemon --start --chuid brewery --exec $DAEMON
53 }
54
55 #
56 # Function that stops the daemon/service
57 #
58 do_stop()
59 {
60 # Return
61 # 0 if daemon has been stopped
62 # 1 if daemon was already stopped
63 # other if daemon could not be stopped or a failure occurred
64 start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
65 }
66
67 #
68 # Function that sends a SIGHUP to the daemon/service
69 #
70 do_reload() {
71 #
72 # If the daemon can reload its configuration without
73 # restarting (for example, when it is sent a SIGHUP),
74 # then implement that here.
75 #
76 return 0
77 }
78
79 case "$1" in
80 start)
81 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
82 do_start
83 case "$?" in
84 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
85 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
86 esac
87 ;;
88 stop)
89 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
90 do_stop
91 case "$?" in
92 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
93 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
94 esac
95 ;;
96 status)
97 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
98 ;;
99 #reload|force-reload)
100 #
101 # If do_reload() is not implemented then leave this commented out
102 # and leave 'force-reload' as an alias for 'restart'.
103 #
104 #log_daemon_msg "Reloading $DESC" "$NAME"
105 #do_reload
106 #log_end_msg $?
107 #;;
108 restart|force-reload)
109 #
110 # If the "reload" option is implemented then remove the
111 # 'force-reload' alias
112 #
113 log_daemon_msg "Restarting $DESC" "$NAME"
114 do_stop
115 case "$?" in
116 0|1)
117 do_start
118 case "$?" in
119 0) log_end_msg 0 ;;
120 1) log_end_msg 1 ;; # Old process is still running
121 *) log_end_msg 1 ;; # Failed to start
122 esac
123 ;;
124 *)
125 # Failed to stop
126 log_end_msg 1
127 ;;
128 esac
129 ;;
130 *)
131 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
132 exit 3
133 ;;
134 esac
135
136 :

mercurial