diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2015-10-28 18:50:43 +0100 |
---|---|---|
committer | spamd-stats <spamd-stats@vm-mail.spline.inf.fu-berlin.de> | 2015-10-28 19:03:50 +0100 |
commit | ca3f250055b35cd3f939b00ec7259862b2d19385 (patch) | |
tree | 876f73fa93b49f63c3641de956caf7561b32ab80 /server.init | |
parent | a7c9ffae3a723bb38eb5badcbcf9f674544a34fa (diff) | |
download | spamd-stats-ca3f250055b35cd3f939b00ec7259862b2d19385.tar.gz spamd-stats-ca3f250055b35cd3f939b00ec7259862b2d19385.tar.bz2 spamd-stats-ca3f250055b35cd3f939b00ec7259862b2d19385.zip |
server.init: Add initscript for spline-startup
Diffstat (limited to 'server.init')
-rw-r--r-- | server.init | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/server.init b/server.init new file mode 100644 index 0000000..d4d5d37 --- /dev/null +++ b/server.init @@ -0,0 +1,87 @@ +#! /bin/sh +DESC="SpamAssassin Statistics Server" +NAME="spamd-stats-server" + +DAEMON="$HOME/bin/server" +DAEMON_ARGS="" +PIDFILE="$HOME/var/$NAME.pid" + +. /lib/lsb/init-functions + +do_start() { + /sbin/start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ + --exec "$DAEMON" --test > /dev/null || return 1 + + /sbin/start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ + --exec "$DAEMON" --background --make-pidfile -- $DAEMON_ARGS || return 2 +} + +killtree() { + local _pid=$1 + local _sig=${2-TERM} + for _child in $(ps -o pid --no-headers --ppid ${_pid}); do + killtree ${_child} ${_sig} + done + kill -${_sig} ${_pid} +} + +do_stop() { + /sbin/start-stop-daemon --stop --quiet --test --pidfile "$PIDFILE" \ + --exec "$DAEMON" && killtree "$(cat "$PIDFILE")" + + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + + rm -f $PIDFILE + return "$RETVAL" +} + +case "$1" in + start) + log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) log_end_msg 0 ;; + 2) log_end_msg 1 ;; + esac + ;; + + stop) + log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) log_end_msg 0 ;; + 2) log_end_msg 1 ;; + esac + ;; + + restart) + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + + status) + status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + + *) + echo "Usage: $0 (start|stop|restart|status)" >&2 + exit 3 + ;; +esac + +: |