blob: bccacc5625fb546d7d1cfccd86c5b5c9dcfbef62 [file] [log] [blame]
#!/bin/sh
#
# slavealloc-staging
#
# chkconfig: 345 85 15
# description: slave allocator daemon
# Source function library.
. /etc/rc.d/init.d/functions
NAME=staging-1079
BASEDIR=/builds/slavealloc/$NAME
lockfile=/var/lock/subsys/slavealloc-$NAME
pidfile=$BASEDIR/twistd.pid
LOGFILE=$BASEDIR/slavealloc.log
TACFILE=$BASEDIR/slavealloc.tac
USER=slavealloc
GROUP=slavealloc
VIRTUALENV=/tools/slavealloc-staging
start() {
[ -x $VIRTUALENV/bin/twistd ] || exit 5
[ -f $TACFILE ] || exit 6
echo -n "starting slavealloc $NAME"
cd $BASEDIR # --rundir doesn't work with the customized .tac logging
daemon $VIRTUALENV/bin/twistd \
--pidfile=$pidfile \
--rundir=$BASEDIR \
--python=$TACFILE \
--logfile=$LOGFILE \
--uid=$USER \
--gid=$GROUP || echo "FAILED"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n "stopping slavealloc $NAME"
kill `cat "${pidfile}"`
echo
rm -f $lockfile
return $retval
}
restart() {
stop && start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
if [ -f $pidfile ]; then
if kill -0 `cat $pidfile`; then
echo "running"
return 0
else
echo "dead but pidfile remains"
return 1
fi
else
if [ -f $lockfile ]; then
echo "dead but lockfile remains"
return 2
else
echo "not running"
return 3
fi
fi
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?