Skip to content

Instantly share code, notes, and snippets.

@crispamares
Last active December 18, 2015 02:48
Show Gist options
  • Save crispamares/5713326 to your computer and use it in GitHub Desktop.
Save crispamares/5713326 to your computer and use it in GitHub Desktop.
Upstart configuration. Starts celeryd when mongodb is running. Tested in Ubuntu 12.04 Contains /etc/init/celery.conf and /etc/default/celeryd
start on started mongodb
stop on stopping mongodb
# limit the retries to max 15 times with timeouts of 5 seconds
respawn limit 15 5
# Time to wait between sending TERM and KILL signals
kill timeout 20
script
DEFAULT_NODE="celery"
DEFAULT_PID_FILE="/var/run/celery/$DEFAULT_NODE.pid"
DEFAULT_LOG_FILE="/var/log/celery/$DEFAULT_NODE.log"
DEFAULT_LOG_LEVEL="INFO"
DEFAULT_CELERYD="/usr/local/bin/celeryd"
CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/celeryd"}
test -f "$CELERY_DEFAULTS" && . "$CELERY_DEFAULTS"
CELERYD_LOG_DIR=`dirname $CELERYD_LOG_FILE`
CELERYD_PID_DIR=`dirname $CELERYD_PID_FILE`
CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
CELERYD=${CELERYD:-$DEFAULT_CELERYD}
CELERYD_NODE=${CELERYD_NODE:-$DEFAULT_NODE}
# Extra start-stop-daemon options, like user/group.
if [ -n "$CELERYD_USER" ]; then
DAEMON_OPTS="$DAEMON_OPTS --chuid $CELERYD_USER"
fi
if [ -n "$CELERYD_GROUP" ]; then
DAEMON_OPTS="$DAEMON_OPTS --group $CELERYD_GROUP"
fi
mkdir -p $CELERYD_LOG_DIR
mkdir -p $CELERYD_PID_DIR
chown $CELERYD_USER:$CELERYD_GROUP $CELERYD_LOG_DIR
chown $CELERYD_USER:$CELERYD_GROUP $CELERYD_PID_DIR
exec start-stop-daemon --start $DAEMON_OPTS \
--exec $CELERYD -- \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
--loglevel="$CELERYD_LOG_LEVEL" \
--workdir="$CELERYD_CHDIR" \
$CELERYD_OPTS
end script
# Name of node to start
# here we have a single node called w1
CELERYD_NODE="w1"
# Where to chdir at start.
CELERYD_CHDIR="/var/www/sas-web/sas/"
# Extra arguments to celeryd
CELERYD_OPTS="--app=jobs -B --schedule=/var/run/celery/celerybeat-schedule"
CELERYD_LOG_FILE="/var/log/celery/$CELERYD_NODE.log"
CELERYD_PID_FILE="/var/run/celery/$CELERYD_NODE.pid"
# Workers should run as an unprivileged user.
CELERYD_USER="www-data"
CELERYD_GROUP="www-data"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment