腌制芹菜

Jin*_*cat 13 python linux celery celeryd

按照此处的说明,我将脚本从github复制到/etc/init.d/celeryd,然后使其可执行;

$ ll /etc/init.d/celeryd
-rwxr-xr-x 1 root root 9481 Feb 19 11:27 /etc/init.d/celeryd*
Run Code Online (Sandbox Code Playgroud)

我按照说明创建了配置文件/ etc/default/celeryd:

# Names of nodes to start
#   most 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"

# 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="/path/to/folder/containing/tasks/"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=3000 --concurrency=3 --config=celeryconfig"

# %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
Run Code Online (Sandbox Code Playgroud)

注意:我在CELERYD_OPTS中添加了--config = celeryconfig部分.

我创建了一个新的用户芹菜

sudo useradd -N -M --system -s /bin/false celery
Run Code Online (Sandbox Code Playgroud)

然后创建组芹菜并添加用户:

$ id celery
uid=999(celery) gid=1005(celery) groups=1005(celery)
Run Code Online (Sandbox Code Playgroud)

我用芹菜芹菜:芹菜夹:

在/ var /运行/芹菜/

在/ var /日志/芹菜/

当我尝试启动该服务时,我没有得到错误的迹象:

$ sudo service celeryd start
celery init v10.0.
Using config script: /etc/default/celeryd
Run Code Online (Sandbox Code Playgroud)

但状态给了我"没有找到pids":

$ sudo service celeryd status
celery init v10.0.
Using config script: /etc/default/celeryd
celeryd is stopped: no pids were found
Run Code Online (Sandbox Code Playgroud)

实际上,ps -ef没有结果,也没有创建PID文件或日志文件:

$ ll /var/run/celery
total 0
drwxr-sr-x  2 celery celery  40 Feb 19 14:13 ./
drwxr-xr-x 16 root   root   620 Feb 19 12:35 ../

$ ll /var/log/celery
total 8
drwxr-sr-x  2 celery celery 4096 Feb 19 14:13 ./
drwxr-xr-x 13 root   root   4096 Feb 19 11:37 ../
Run Code Online (Sandbox Code Playgroud)

附加信息:

$ pip freeze | grep celery
celery==3.1.9
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我应该在哪里寻找更多线索,为什么芹菜没有开始?

rav*_*shi 16

我复制了你的步骤,结果出现了同样的问题.问题是芹菜用户没有外壳.

sudo useradd -N -M --system -s /bin/false celery
Run Code Online (Sandbox Code Playgroud)

更改-s /bin/false-s /bin/bash解决问题.原因是celeryd init脚本使用celery用户的shell来执行celery命令.没有shell,下面的su命令会以静默方式退出.

_chuid () {
    su "$CELERYD_USER" -c "$CELERYD_MULTI $*"
}
Run Code Online (Sandbox Code Playgroud)