chiark / gitweb /
0cac9ac5362f407f8868af89f8cd5f798b163758
[hippotat.git] / debian / hippotat-server.hippotatd.init
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:             hippotatd
5 # Required-Start:       $syslog $network $local_fs userv
6 # Required-Stop:        $syslog $network $local_fs
7 # Default-Start:        2 3 4 5
8 # Default-Stop:         0 1 6
9 # Short-Description:    hippotatd
10 # Description:          Asinine IP over HTTP server
11 ### END INIT INFO
12
13 E: hippotat-server: init.d-script-sourcing-without-test etc/init.d/hippotatd:25 /etc/default/hippotatd
14 E: hippotat-client: missing-dependency-on-libc needed by usr/bin/hippotat
15 E: hippotat-server: missing-dependency-on-libc needed by usr/sbin/hippotatd
16
17 DAEMON=/usr/sbin/hippotatd
18 MAIN_CONFIG=/etc/hippotat/main.cfg
19 USER=_hippotat
20 PIDFILE=/var/run/hippotat/hippotatd.pid
21 LOGFACILITY=daemon
22 CHECK_FIREWALL=true
23 # HIPPOTATD_ARGS
24 AS_USER=as_user_userv
25 DESCRIPTION='Asinine IP over HTTP server'
26 if type authbind >/dev/null 2>&1; then AUTHBIND=authbind; fi
27
28 test -e /etc/default/hippotatd && . /etc/default/hippotatd
29
30 set -e
31
32 test -f $DAEMON || exit 0
33 egrep '^[^      #]' $MAIN_CONFIG >/dev/null 2>&1 || exit 0
34
35 . /lib/lsb/init-functions
36
37 as_user_userv () {
38         userv --override '
39                 execute-from-path
40                 no-suppress-args
41         ' $USER "$@"
42 }
43
44 ssd () {
45         set +e
46         start-stop-daemon --quiet --user $USER --pidfile=$PIDFILE "$@"
47         rc=$?
48         set -e
49 }
50 ensure_dirs () {
51         pidfiledir=${PIDFILE%/*}
52         if test -d ${pidfiledir}; then return; fi
53         mkdir -m 755 $pidfiledir
54         chown $USER $pidfiledir
55 }
56
57 dump_firewall () {
58         iptables -L -v -n
59 }
60
61 print_config () {
62         $AS_USER $DAEMON $HIPPOTATD_ARGS --print-config "$1"
63 }
64
65 check_firewall () {
66         vnetwork=$(print_config vnetwork)
67         if dump_firewall | fgrep " $vnetwork " >/dev/null; then :; else
68                 log_failure_msg \
69  "no entry in firewall for insecure vnetwork $vnetwork"
70                 exit 1
71         fi
72 }
73
74 do_start () {
75         check_firewall
76         ensure_dirs
77         ssd     --chuid $USER --start                           \
78                 --startas /bin/sh -- -ec '"$@"' x               \
79                 $AUTHBIND $DAEMON --daemon --pidfile=$PIDFILE   \
80                 --syslog-facility=$LOGFACILITY $HIPPOTATD_ARGS
81 }
82 do_stop () {
83         ssd     --stop --oknodo --retry 5
84 }
85
86 case "$1" in
87 start)
88         log_daemon_msg "Starting $DESCRIPTION" hippotatd
89         do_start
90         log_end_msg $rc
91         exit $rc
92         ;;
93
94 stop)
95         log_daemon_msg "Stopping $DESCRIPTION" hippotatd
96         do_stop
97         log_end_msg $rc
98         exit $rc
99         ;;
100
101 restart|force-reload)
102         log_daemon_msg "Restarting $DESCRIPTION" hippotatd
103         do_stop
104         sleep 1
105         do_start
106         log_end_msg $rc
107         ;;
108
109 reload)
110         log_failure_msg "Cannot reload hippotat - need restart"
111         exit 1
112         ;;
113
114 *)
115         echo >&2 "$0: unknown action $1"
116         exit 1
117         ;;
118
119 esac
120
121 exit 0