0x01 Use Guide of Celery Daemon

In production environment I need celery runing as daemon process. According to the official document,there are several ways to use, such as generic init scripts,systemd,supervisord and so on.

0x02 Use init script

We can get the script from extra/generic-init.d. You need add the file to /etc/init/ named as celeryd. Besides you need motified the configure file /etc/default/celeryd. To configure this script to run the worker properly you probaly need to at last tell it where to change dierctory when ti starts.
This is an expample configration for a Python project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS (see `celery multi --help` for examples):
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app"

# Where to chdir at start.
CELERYD_CHDIR="/opt/Myproject/"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.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="celery"
CELERYD_GROUP="celery"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

Then this is my configration for my project:

1
2
3
4
5
6
7
8
9
CELERYD_NODES="worker1"
CELERY_BIN="/usr/local/bin/celery"
CELERYD_CHDIR="/root/Documents/WebEye"
CELERYD_OPTS="--config=confs.worker.workerceleryconf --time-limit=300 --concurrency=8"
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"
CELERYD_USER="root"
CELERYD_GROUP="root"
CELERY_CREATE_DIRS=1

Then you could use service celeryd {start|stop|restart|status} to get your information

0x03 Thanks

在此我要感谢诸位陈老师给我悉心的帮助和对我耐心而细致的指导。他们在我工作中给了我许多宝贵的意见和建议。同时也要感谢自己遇到困难的时候没有一蹶不振,取而代之的是找到了最好的方法来解决问题。最后,感谢生我养我的父母。谢谢他们给了我无私的爱,为我人生道路付出的巨大牺牲和努力。