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