Wednesday 27 June 2018

Deploy celery on Debian 8 using upstart

Make an upstart conf file:

nano /etc/init/celery.conf

Insert in it:

description "Celery application server handling myproject"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid john
setgid www-data
chdir /path/to/django/proj
exec bash celery.sh
Put `celery.sh` in /path/to/django/proj


CELERY_BIN="/home/john/.projenv/bin/celery"


# App instance to use
CELERY_APP="proj"
# Where to chdir at start.
CELERYD_CHDIR="/path/to/django/proj"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=1"
# %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists (e.g., nobody).
CELERYD_USER="john"
CELERYD_GROUP="www-data"
# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
export SECRET_KEY="somekey"

Start the deamon:

service celery start

That's it!‌