Created
July 1, 2015 17:30
-
-
Save jg75/81e403a7b303ee57e563 to your computer and use it in GitHub Desktop.
celery worker init.d script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
PNAME="$(basename $0)" | |
USER="jgarner1" | |
PIDFILE="$HOME/messaging/celery.pid" | |
LOGFILE="$HOME/messaging/celery.log" | |
AUTOSCALE="1,1" | |
start() { | |
if [ $# -eq 1 ] | |
then | |
AUTOSCALE=$1 | |
fi | |
nohup celery worker --app=tasks \ | |
--hostname=%h \ | |
--logfile=$LOGFILE \ | |
--pidfile=$PIDFILE \ | |
--autoscale=$AUTOSCALE > $LOGFILE 2> $LOGFILE & | |
} | |
stop() { | |
if [ -s $PIDFILE ] | |
then | |
ps -u $USER -o pid,ppid | awk -v ppid=$(cat $PIDFILE) '{ | |
if ($1 == ppid || $2 == ppid) { | |
print $1 | |
} | |
}' | xargs kill -9 | |
fi | |
} | |
usage() { | |
echo "Usage: $PNAME stop|start|restart" | |
exit 2 | |
} | |
case $1 in | |
stop) stop | |
;; | |
start) shift | |
start $@ | |
;; | |
restart) shift | |
stop | |
start $@ | |
;; | |
*) usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment