diff -r 5d027884a9d3 -r 7b0d87ef5e63 gmyth-stream/server/data/gmsd --- a/gmyth-stream/server/data/gmsd Tue Sep 18 13:45:04 2007 +0100 +++ b/gmyth-stream/server/data/gmsd Wed Dec 16 10:06:21 2009 +0000 @@ -1,62 +1,73 @@ #!/bin/sh -PROGRAM_NAME=GMS -PROGRAM_BIN=/usr/bin/gms.py -PIDFILE=/var/run/gms.pid -LOGFILE=/var/log/gms.log - -test -x $PROGRAM_BIN || exit 0 set -e +DAEMON=/usr/bin/gms.py +PIDDIR=/var/run/gms +PIDFILE=$PIDDIR.pid +LOGFILE=/var/log/gms.log +DAEMONUSER=root +NAME=gms +DESC="GMyth transcode server" + +test -x $DAEMON || exit 0 . /lib/lsb/init-functions . /etc/default/rcS +# Source defaults file; edit that file to configure this script. +ENABLED=1 +PARAMS="-d" + +start_it_up() +{ + if [ ! -d $PIDDIR ]; then + mkdir -p $PIDDIR + chown $DAEMONUSER $PIDDIR + chgrp $DAEMONUSER $PIDDIR + fi + if [ -e $PIDFILE ]; then + PIDDIR=/proc/$(cat $PIDFILE) + if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then + log_success_msg "$DESC already started; not starting." + return + else + log_success_msg "Removing stale PID file $PIDFILE." + rm -f $PIDFILE + fi + fi + + log_daemon_msg "Starting $DESC" "$NAME" + start-stop-daemon --start --quiet --pidfile $PIDFILE \ + --user $DAEMONUSER --exec $DAEMON -- $PARAMS + log_end_msg $? +} + +shut_it_down() +{ + log_daemon_msg "Stopping $DESC" "$NAME" + start-stop-daemon --stop --retry 60 --quiet --oknodo --pidfile $PIDFILE \ + --user $DAEMONUSER + log_end_msg $? + rm -f $PIDFILE +} + case $1 in start) - echo -n "Starting $PROGRAM_NAME: " - if [ -f $PIDFILE ] - then - PID=`cat $PIDFILE` - - if ps ax | grep -q "^$PID" - then - echo "$PROGRAM_NAME already running." - else - rm -f $PIDFILE - $PROGRAM_BIN -d > $LOGFILE 2> $LOGFILE - echo "OK" - fi - else - $PROGRAM_BIN -d > $LOGFILE 2> $LOGFILE - echo "OK" - fi + start_it_up ;; stop) - echo -n "Stopping $PROGRAM_NAME: " - if [ -f $PIDFILE ] - then - PID=`cat $PIDFILE` - if ps -p "$PID" > /dev/null - then - kill -9 $PID - fi - rm $PIDFILE - echo "OK" - else - echo "No $PROGRAM_NAME found running; no killed." - fi + shut_it_down ;; restart) - $0 stop - sleep 1 - $0 start + shut_it_down + start_it_up ;; *) - log_success_msg "Usage: $0 {stop|start|restart}" - exit 1 + echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2 + exit 2 ;; esac