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