Skip to content

Instantly share code, notes, and snippets.

@keithshep
Created January 6, 2016 17:06
Show Gist options
  • Save keithshep/330d5e09e911c2a588da to your computer and use it in GitHub Desktop.
Save keithshep/330d5e09e911c2a588da to your computer and use it in GitHub Desktop.
example init.d file for starting & stopping celery within a virtualenv
#!/bin/sh
#
# chkconfig: 345 95 05
# description: celery daemon configured to work with the haploqa application
# If we're invoked via SysV-style runlevel scripts we need to follow the
# link from rcX.d before working out the script name.
if [[ `dirname $0` == /etc/rc*.d ]]; then
target="$(readlink $0)"
else
target=$0
fi
prog="$(basename $target)"
source /var/haploqa/haploqa-venv/bin/activate
export PYTHONPATH=/var/haploqa/haploqa-webapp/src
stop() {
echo -n $"Stopping $prog: "
celery multi stop haploqa \
--uid=apache --gid=apache \
--pidfile="/var/haploqa/celery-run/%N.pid" \
--logfile="/var/haploqa/celery-run/%N.log"
}
start() {
echo -n $"Starting $prog: "
celery multi start haploqa \
--uid=apache --gid=apache \
--pidfile="/var/haploqa/celery-run/%N.pid" \
--logfile="/var/haploqa/celery-run/%N.log" \
-A haploqa.haploqaapp.celery
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop && start
;;
*)
echo "Usage: /etc/init.d/$prog {start|stop|restart}"
exit 3
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment