| 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/hippotat |
| 14 | MASTER_CONFIG=/etc/hippotat/master.cfg |
| 15 | USER=Debian-hippotat |
| 16 | PIDFILE=/var/run/hippotat/hippotatd.pid |
| 17 | LOGFACILITY=daemon |
| 18 | # HIPPOTATD_ARGS |
| 19 | |
| 20 | . /etc/default/hippotatd |
| 21 | |
| 22 | test -f $DAEMON || exit 0 |
| 23 | egrep '^[^ #]' $MASTER_CONFIG >/dev/null 2>&1 || exit 0 |
| 24 | |
| 25 | . /lib/lsb/init-functions |
| 26 | |
| 27 | ssd () { |
| 28 | set +e |
| 29 | start-stop-daemon --start --quiet --user $USER --pidfile=$PIDFILE "$@" |
| 30 | rc=$? |
| 31 | set -e |
| 32 | } |
| 33 | ensure_dirs () { |
| 34 | pidfiledir=${PIDFILE%/*} |
| 35 | if test -d ${pidfiledir}; then return; fi |
| 36 | mkdir -m 755 $pidfiledir |
| 37 | chown $USER $pidfiledir |
| 38 | } |
| 39 | |
| 40 | do_start () { |
| 41 | ensure_dirs |
| 42 | ssd --chuid $USER --startas \ |
| 43 | $DAEMON --daemon --pidfile=$PIDFILE \ |
| 44 | --syslog-facility=$LOGFACILITY $HIPPOTATD_ARGS |
| 45 | } |
| 46 | do_stop () { |
| 47 | ssd --stop --retry 5 |
| 48 | } |
| 49 | |
| 50 | case "$1" in |
| 51 | start) |
| 52 | log_daemon_msg "Starting IP over HTTP server" hippotatd |
| 53 | do_start |
| 54 | log_end_msg $rc |
| 55 | ;; |
| 56 | |
| 57 | stop) |
| 58 | log_daemon_msg "Stopping IP over HTTP server" hippotatd |
| 59 | do_stop |
| 60 | log_end_msg $rc |
| 61 | ;; |
| 62 | |
| 63 | restart|force-reload) |
| 64 | log_daemon_msg "Restarting IP over HTTP server" hippotatd |
| 65 | do_stop |
| 66 | sleep 1 |
| 67 | do_start |
| 68 | log_end_msg $rc |
| 69 | ;; |
| 70 | |
| 71 | reload) |
| 72 | log_failure_msg "Cannot reload hippotat - need restart" |
| 73 | exit 1 |
| 74 | ;; |
| 75 | |
| 76 | *) |
| 77 | echo >&2 "$0: unknown action $1" |
| 78 | exit 1 |
| 79 | ;; |
| 80 | |
| 81 | esac |
| 82 | |
| 83 | exit 0 |