tools/bmsd.init

changeset 574
b436e3d8d83a
child 575
fd9e4838648f
equal deleted inserted replaced
573:c4c891d5c4f8 574:b436e3d8d83a
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 su - brewery -c "$DAEMON" >/dev/null 2>/dev/null
49 }
50
51 #
52 # Function that stops the daemon/service
53 #
54 do_stop()
55 {
56 [ -f $PIDFILE ] && kill $(cat $PIDFILE)
57 RETVAL="$?"
58 return "$RETVAL"
59 }
60
61 #
62 # Function that sends a SIGHUP to the daemon/service
63 #
64 do_reload() {
65 #
66 # If the daemon can reload its configuration without
67 # restarting (for example, when it is sent a SIGHUP),
68 # then implement that here.
69 #
70 return 0
71 }
72
73 case "$1" in
74 start)
75 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
76 do_start
77 case "$?" in
78 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
79 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
80 esac
81 ;;
82 stop)
83 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
84 do_stop
85 case "$?" in
86 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
87 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
88 esac
89 ;;
90 status)
91 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
92 ;;
93 #reload|force-reload)
94 #
95 # If do_reload() is not implemented then leave this commented out
96 # and leave 'force-reload' as an alias for 'restart'.
97 #
98 #log_daemon_msg "Reloading $DESC" "$NAME"
99 #do_reload
100 #log_end_msg $?
101 #;;
102 restart|force-reload)
103 #
104 # If the "reload" option is implemented then remove the
105 # 'force-reload' alias
106 #
107 log_daemon_msg "Restarting $DESC" "$NAME"
108 do_stop
109 case "$?" in
110 0|1)
111 do_start
112 case "$?" in
113 0) log_end_msg 0 ;;
114 1) log_end_msg 1 ;; # Old process is still running
115 *) log_end_msg 1 ;; # Failed to start
116 esac
117 ;;
118 *)
119 # Failed to stop
120 log_end_msg 1
121 ;;
122 esac
123 ;;
124 *)
125 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
126 exit 3
127 ;;
128 esac
129
130 :

mercurial