Celery作为守护进程停止运行

时间:2016-05-06 17:25:32

标签: python linux django celery daemon

我在centos linux服务器上使用redis安装了celery。

我使用以下命令启动芹菜工作者:

celery multi start worker1 -A proj -Q lopri,lopri2 -l info --pidfile="$HOME/run/celery/%n.pid" --logfile="$HOME/log/celery/%n.log"

问题是,几个小时后,工作人员不再响应任务创建。我必须重新启动工作程序才能再次处理任务。

这是celery设置文件,位于/ etc / default / celeryd:

# 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"

#django settings
#export DJANGO_SETTINGS_MODULE="settings"

# Where to chdir at start.
CELERYD_CHDIR="/var/www/html/proj/"

# 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="ec2-user"
CELERYD_GROUP="ec2-user"

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

关于发生的事情可能有线索的一个问题是我必须从项目文件夹中运行“start”命令,否则我收到错误:

  

ImportError:没有名为proj的模块

CELERYD_CHDIR设置不应该解决这个问题吗?这是否意味着我的启动命令没有使用这个芹菜默认设置文件?

感谢您对此有所了解。

1 个答案:

答案 0 :(得分:2)

如果您通过命令行运行celery,则您的设置文件几乎没用。我的意思是,他们没有被应用,这就是为什么你得到一个错误,说你的项目无法导入。

这是将celery作为守护进程运行的脚本: https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd

如您所见:https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd#L56 这就是脚本导入设置的地方。

我不太确定为什么你的芹菜在几个小时后停止工作,但这表明你并没有真正作为一个守护进程运行。 也许用设置设置属性init.d脚本可以解决这个问题,但我对此表示怀疑。