Add boardvoting init script
[cacert-puppet.git] / sitemodules / profiles / files / cacert_boardvoting / init.sh
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides: boardvoting
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: CAcert board voting system
9 # Description: CAcert board voting system
10 ### END INIT INFO
11
12 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
13
14 BASE=boardvoting
15
16 BOARDVOTING=/usr/local/bin/cacert-boardvoting
17 BOARDVOTING_PIDFILE=/var/run/$BASE.pid
18 BOARDVOTING_LOGFILE=/var/log/$BASE.log
19 BOARDVOTING_OPTS=
20 BOARDVOTING_DESC="Boardvoting"
21
22 # Get lsb functions
23 . /lib/lsb/init-functions
24
25 if [ -f /etc/default/$BASE ]; then
26 . /etc/default/$BASE
27 fi
28
29 # Check boardvoting is present
30 if [ ! -x $BOARDVOTING ]; then
31 log_failure_msg "$BOARDVOTING not present or not executable"
32 exit 1
33 fi
34
35 fail_unless_root() {
36 if [ "$(id -u)" != '0' ]; then
37 log_failure_msg "$BOARDVOTING_DESC must be run as root"
38 exit 1
39 fi
40 }
41
42 case "$1" in
43 start)
44 fail_unless_root
45
46 touch "$BOARDVOTING_LOGFILE"
47 chown boardvoting:adm "$BOARDVOTING_LOGFILE"
48
49 log_begin_msg "Starting $BOARDVOTING_DESC: $BOARDVOTING"
50 start-stop-daemon --start --background --no-close \
51 --exec "$BOARDVOTING" \
52 --pidfile "$BOARDVOTING_PIDFILE" \
53 --make-pidfile \
54 -- \
55 $BOARDVOTING_OPTS >> "$BOARDVOTING_LOGFILE" 2>&1
56 log_end_msg $?
57 ;;
58
59 stop)
60 fail_unless_root
61 if [ -f "$BOARDVOTING_PIDFILE" ]; then
62 start-stop-daemon --stop --pidfile "$BOARDVOTING_PIDFILE" --retry 5
63 log_end_msg $?
64 else
65 log_warning_msg "$BOARDVOTING_DESC already stopped - file $BOARDVOTING_PIDFILE not found."
66 fi
67 ;;
68
69 restart)
70 fail_unless_root
71 boardvoting_pid=`cat "$BOARDVOTING_PIDFILE" 2> /dev/null`
72 [ -n "$boardvoting_pid" ] \
73 && ps -p $boardvoting_pid > /dev/null 2>&1 \
74 && $0 stop
75 $0 start
76 ;;
77
78 force-reload)
79 fail_unless_root
80 $0 restart
81 ;;
82
83 status)
84 status_of_proc -p "$BOARDVOTING_PIDFILE" "$BOARDVOTING" "$BOARDVOTING_DESC"
85 ;;
86
87 *)
88 echo "Usage: service boardvoting {start|stop|restart|force-reload|status}"
89 exit 1
90 ;;
91 esac