X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=pl_mom;fp=pl_mom;h=a41c481a9f25075337832f285fe3f43ccea12044;hb=0b94296a0de4e93a3ebb4c0747ea2be4e29ae674;hp=0000000000000000000000000000000000000000;hpb=23ef533708ecb5f8bb98672527c70119dcae88cc;p=mom.git diff --git a/pl_mom b/pl_mom new file mode 100755 index 0000000..a41c481 --- /dev/null +++ b/pl_mom @@ -0,0 +1,74 @@ +#!/bin/sh +# +# chkconfig: 345 98 02 +# description: pl_mom (daemon of death) startup script +# + +CODE='/usr/local/planetlab/bin/pl_mom.pl' +PROC='pl_mom' + +. /etc/rc.d/init.d/functions + +RETVAL=0 + +pidfile=/var/run/$PROC.pid + +check_status() { + pid=`cat $pidfile 2>/dev/null` + # + # this eliminates a race condition between checking existence of pidfile + # and reading its value + # + [ -n "$pid" -a -d /proc/$pid ] +} + +case "$1" in + start) + echo -n "starting $PROC:" + [ -r $CODE ] || action "code missing" /bin/false || exit 1 + pid=`cat $pidfile 2>/dev/null` + if [ -n "$pid" ]; then + # check whether process really exists + # yes - don't try to start + [ -d /proc/$pid ] && action "already running" /bin/true && exit 1 + + # no - PID file is stale + rm -f $pidfile + fi + + $CODE + sleep 1 + + cmd=success + check_status || cmd=failure + $cmd "$PROC startup" + echo + ;; + + stop) + echo -n "shutting down $PROC: " + check_status && kill -TERM -`cat $pidfile` && sleep 1 + cmd=failure + check_status || cmd=success && rm -f $pidfile + $cmd "$PROC shutdown" + RETVAL=0 + echo + ;; + + restart|reload) + $0 stop + $0 start + RETVAL=$? + ;; + + status) + check_status && echo 'running' && exit 0 || \ + echo 'not running' && exit 1 + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 +esac + +exit $RETVAL