Define user and workdir for boardvoting service
[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_WORKDIR=/var/lib/$BASE
20 BOARDVOTING_USER=$BASE
21 BOARDVOTING_OPTS=
22 BOARDVOTING_DESC="Boardvoting"
23
24 # Get lsb functions
25 . /lib/lsb/init-functions
26
27 if [ -f /etc/default/$BASE ]; then
28 . /etc/default/$BASE
29 fi
30
31 # Check boardvoting is present
32 if [ ! -x $BOARDVOTING ]; then
33 log_failure_msg "$BOARDVOTING not present or not executable"
34 exit 1
35 fi
36
37 fail_unless_root() {
38 if [ "$(id -u)" != '0' ]; then
39 log_failure_msg "$BOARDVOTING_DESC must be run as root"
40 exit 1
41 fi
42 }
43
44 case "$1" in
45 start)
46 fail_unless_root
47
48 touch "$BOARDVOTING_LOGFILE"
49 chown boardvoting:adm "$BOARDVOTING_LOGFILE"
50
51 log_begin_msg "Starting $BOARDVOTING_DESC: $BOARDVOTING"
52 start-stop-daemon --start --background --no-close \
53 --exec "$BOARDVOTING" \
54 --user "$BOARDVOTING_USER" \
55 --pidfile "$BOARDVOTING_PIDFILE" \
56 --chdir "$BOARDVOTING_WORKDIR" \
57 --make-pidfile \
58 -- \
59 $BOARDVOTING_OPTS >> "$BOARDVOTING_LOGFILE" 2>&1
60 log_end_msg $?
61 ;;
62
63 stop)
64 fail_unless_root
65 if [ -f "$BOARDVOTING_PIDFILE" ]; then
66 start-stop-daemon --stop --pidfile "$BOARDVOTING_PIDFILE" --retry 5
67 log_end_msg $?
68 else
69 log_warning_msg "$BOARDVOTING_DESC already stopped - file $BOARDVOTING_PIDFILE not found."
70 fi
71 ;;
72
73 restart)
74 fail_unless_root
75 boardvoting_pid=`cat "$BOARDVOTING_PIDFILE" 2> /dev/null`
76 [ -n "$boardvoting_pid" ] \
77 && ps -p $boardvoting_pid > /dev/null 2>&1 \
78 && $0 stop
79 $0 start
80 ;;
81
82 force-reload)
83 fail_unless_root
84 $0 restart
85 ;;
86
87 status)
88 status_of_proc -p "$BOARDVOTING_PIDFILE" "$BOARDVOTING" "$BOARDVOTING_DESC"
89 ;;
90
91 *)
92 echo "Usage: service boardvoting {start|stop|restart|force-reload|status}"
93 exit 1
94 ;;
95 esac