From fff76b5cc349008948faa130242fc49834b5ef91 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Sat, 25 Aug 2012 18:12:39 -0700 Subject: [PATCH] Example init script for mumo --- init-script | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 init-script diff --git a/init-script b/init-script new file mode 100755 index 0000000..baf1968 --- /dev/null +++ b/init-script @@ -0,0 +1,108 @@ +#! /bin/sh +# +### BEGIN INIT INFO +# Provides: mumo +# Required-Start: $network $local_fs $remote_fs dbus +# Required-Stop: $network $local_fs $remote_fs dbus +# Should-Start: $mysql +# Should-Stop: $mysql +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Mumo bot for Mumble +### END INIT INFO + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +NAME=mumo +DESC="Mumo bot for Mumble" +WORKDIR=/opt/mumo +PIDDIR=$WORKDIR +PIDFILE=$PIDDIR/mumo.pid +DAEMON=/usr/bin/python +USER=mumo +GROUP=mumo + +test -x $DAEMON || exit 0 + +INIFILE=$WORKDIR/mumo.ini +DAEMON_OPTS="$WORKDIR/mumo.py --daemon --ini $INIFILE" + +# Include defaults if available +if [ -f /etc/default/$NAME ] ; then + . /etc/default/$NAME +fi + +. /lib/init/vars.sh +. /lib/lsb/init-functions + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + [ -d $PIDDIR ] || install -o $USER -d $PIDDIR + start-stop-daemon --start --quiet \ + --chdir $WORKDIR \ + --pidfile $PIDFILE \ + --chuid $USER:$GROUP \ + --exec $DAEMON \ + -- $DAEMON_OPTS + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + start-stop-daemon --stop --quiet \ + --chdir $WORKDIR \ + --pidfile $PIDFILE \ + --user $USER \ + --exec $DAEMON + case "$?" in + 0|1) rm -f $PIDFILE + [ "$VERBOSE" != no ] && log_end_msg 0 + ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + force-reload) + start-stop-daemon --stop --test --quiet \ + --chdir $WORKDIR \ + --pidfile $PIDFILE \ + --user $USER \ + --exec $DAEMON \ + && $0 restart || exit 0 + ;; + restart) + [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME" + start-stop-daemon --stop --quiet \ + --chdir $WORKDIR \ + --pidfile $PIDFILE \ + --user $USER \ + --exec $DAEMON + case "$?" in + 0|1) + [ -d $PIDDIR ] || install -o $USER -d $PIDDIR + rm -f $PIDFILE + start-stop-daemon --start --quiet \ + --chdir $WORKDIR \ + --pidfile $PIDFILE \ + --chuid $USER:$GROUP \ + --exec $DAEMON \ + -- $DAEMON_OPTS + case "$?" in + 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + *) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + *) + [ "$VERBOSE" != no ] && log_end_msg 0 + ;; + esac + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +exit 0