diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2015-10-28 19:28:33 +0100 |
---|---|---|
committer | spamd-stats <spamd-stats@vm-mail.spline.inf.fu-berlin.de> | 2015-10-28 19:28:33 +0100 |
commit | 1731ff56f6337e28d5575954433d472804d46f45 (patch) | |
tree | b0094d4eb8144db0039e631099fd60fbec51b390 /contrib/server.init | |
parent | ca3f250055b35cd3f939b00ec7259862b2d19385 (diff) | |
download | spamd-stats-1731ff56f6337e28d5575954433d472804d46f45.tar.gz spamd-stats-1731ff56f6337e28d5575954433d472804d46f45.tar.bz2 spamd-stats-1731ff56f6337e28d5575954433d472804d46f45.zip |
contrib: Move init script into contrib
Diffstat (limited to 'contrib/server.init')
-rw-r--r-- | contrib/server.init | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/contrib/server.init b/contrib/server.init new file mode 100644 index 0000000..b331c24 --- /dev/null +++ b/contrib/server.init @@ -0,0 +1,89 @@ +#! /bin/sh +DESC="SpamAssassin Statistics Server" +NAME="spamd-stats-server" + +EXEC="/usr/bin/perl" +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 "$EXEC" --startas "$DAEMON" --test > /dev/null || return 1 + + /sbin/start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ + --exec "$EXEC" --startas "$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 "$EXEC" --startas "$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 + +: |