1.1 --- a/gmyth-stream/server/data/gmsd Fri Feb 08 00:03:03 2008 +0000
1.2 +++ b/gmyth-stream/server/data/gmsd Thu Feb 14 16:13:51 2008 +0000
1.3 @@ -1,62 +1,73 @@
1.4 #!/bin/sh
1.5
1.6 -PROGRAM_NAME=GMS
1.7 -PROGRAM_BIN=/usr/bin/gms.py
1.8 -PIDFILE=/var/run/gms.pid
1.9 -LOGFILE=/var/log/gms.log
1.10 -
1.11 -test -x $PROGRAM_BIN || exit 0
1.12
1.13 set -e
1.14
1.15 +DAEMON=/usr/bin/gms.py
1.16 +PIDDIR=/var/run/gms
1.17 +PIDFILE=$PIDDIR.pid
1.18 +LOGFILE=/var/log/gms.log
1.19 +DAEMONUSER=root
1.20 +NAME=gms
1.21 +DESC="GMyth transcode server"
1.22 +
1.23 +test -x $DAEMON || exit 0
1.24 . /lib/lsb/init-functions
1.25 . /etc/default/rcS
1.26
1.27 +# Source defaults file; edit that file to configure this script.
1.28 +ENABLED=1
1.29 +PARAMS="-d"
1.30 +
1.31 +start_it_up()
1.32 +{
1.33 + if [ ! -d $PIDDIR ]; then
1.34 + mkdir -p $PIDDIR
1.35 + chown $DAEMONUSER $PIDDIR
1.36 + chgrp $DAEMONUSER $PIDDIR
1.37 + fi
1.38 + if [ -e $PIDFILE ]; then
1.39 + PIDDIR=/proc/$(cat $PIDFILE)
1.40 + if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then
1.41 + log_success_msg "$DESC already started; not starting."
1.42 + return
1.43 + else
1.44 + log_success_msg "Removing stale PID file $PIDFILE."
1.45 + rm -f $PIDFILE
1.46 + fi
1.47 + fi
1.48 +
1.49 + log_daemon_msg "Starting $DESC" "$NAME"
1.50 + start-stop-daemon --start --quiet --pidfile $PIDFILE \
1.51 + --user $DAEMONUSER --exec $DAEMON -- $PARAMS
1.52 + log_end_msg $?
1.53 +}
1.54 +
1.55 +shut_it_down()
1.56 +{
1.57 + log_daemon_msg "Stopping $DESC" "$NAME"
1.58 + start-stop-daemon --stop --retry 60 --quiet --oknodo --pidfile $PIDFILE \
1.59 + --user $DAEMONUSER
1.60 + log_end_msg $?
1.61 + rm -f $PIDFILE
1.62 +}
1.63 +
1.64 case $1 in
1.65 start)
1.66 - echo -n "Starting $PROGRAM_NAME: "
1.67 - if [ -f $PIDFILE ]
1.68 - then
1.69 - PID=`cat $PIDFILE`
1.70 -
1.71 - if ps ax | grep -q "^$PID"
1.72 - then
1.73 - echo "$PROGRAM_NAME already running."
1.74 - else
1.75 - rm -f $PIDFILE
1.76 - $PROGRAM_BIN -d > $LOGFILE 2> $LOGFILE
1.77 - echo "OK"
1.78 - fi
1.79 - else
1.80 - $PROGRAM_BIN -d > $LOGFILE 2> $LOGFILE
1.81 - echo "OK"
1.82 - fi
1.83 + start_it_up
1.84 ;;
1.85
1.86 stop)
1.87 - echo -n "Stopping $PROGRAM_NAME: "
1.88 - if [ -f $PIDFILE ]
1.89 - then
1.90 - PID=`cat $PIDFILE`
1.91 - if ps -p "$PID" > /dev/null
1.92 - then
1.93 - kill -9 $PID
1.94 - fi
1.95 - rm $PIDFILE
1.96 - echo "OK"
1.97 - else
1.98 - echo "No $PROGRAM_NAME found running; no killed."
1.99 - fi
1.100 + shut_it_down
1.101 ;;
1.102
1.103 restart)
1.104 - $0 stop
1.105 - sleep 1
1.106 - $0 start
1.107 + shut_it_down
1.108 + start_it_up
1.109 ;;
1.110
1.111 *)
1.112 - log_success_msg "Usage: $0 {stop|start|restart}"
1.113 - exit 1
1.114 + echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
1.115 + exit 2
1.116 ;;
1.117 esac