Skip to content

Instantly share code, notes, and snippets.

@ThiefMaster
Created February 25, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThiefMaster/9212125 to your computer and use it in GitHub Desktop.
Save ThiefMaster/9212125 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# indico-scheduler init file for starting up the indico scheduler
#
# chkconfig: - 20 80
# description: Starts and stops the zodb daemon.
### BEGIN INIT INFO
# Provides: indico-scheduler
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the Indico scheduler
# Description: Indico scheduler
### END INIT INFO
name="indico_scheduler"
exec="/usr/bin/$name"
exec="/home/adrian/dev/indico/env/bin/indico_scheduler" # TODO remove
start() {
[ -x $exec ] || exit 5
echo -n $"Starting $name: "
$exec start
retval=$?
echo
return $retval
}
stop() {
echo -n $"Stopping $name: "
$exec stop
retval=$?
echo
# Don't check process list if the scheduler was on another machine
[ $1 -eq 2 ] && return $retval
# Check processes and kill if necessary
pid=$(pgrep -f indico_scheduler)
[ $? -ne 0 ] && return 0
sleep 2
echo "Scheduler is still running, killing $pid"
kill -9 $pid
pgrep -f indico_scheduler || return 0 && return 1
}
restart() {
stop $1
start
}
reload() {
false
}
rh_status() {
pid=$($exec check -q)
retval=$?
if [ $retval -eq 0 ]; then
echo "$name (pid $pid) is running"
elif [ $retval -eq 1 ]; then
echo "$name is not running"
elif [ $retval -eq 2 ]; then
echo "$name is broken or running on another machine!"
fi
return $retval
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q
retval=$?
if [ $retval -eq 2 ]; then
echo 'Error, scheduler might be running on another machine or broken'
exit 1
fi
[ $retval -eq 1 ] || exit 0
$1
;;
stop)
rh_status_q
retval=$?
[ $retval -eq 2 ] && echo 'Warning, scheduler might be running on another machine or broken'
[ $retval -eq 1 ] && exit 0
$1 $retval
;;
restart)
rh_status_q
retval=$?
if [ $retval -eq 2 ]; then
echo 'Error, scheduler might be running on another machine or broken'
exit 1
fi
$1 $retval
;;
reload)
rh_status_q
[ $? -eq 1 ] && 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}"
exit 2
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment