芹菜守护 [英] Daemonizing celery
问题描述
在此处中找到了以下说明,我复制了
Following instructions found here, I copied the script from github into /etc/init.d/celeryd, then made it executable;
$ ll /etc/init.d/celeryd
-rwxr-xr-x 1 root root 9481 Feb 19 11:27 /etc/init.d/celeryd*
我按照说明创建了配置文件/etc/default/celeryd :
I created config file /etc/default/celeryd as per instructions:
# 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
注意:我在CELERYD_OPTS中添加了-config = celeryconfig 部分.
Note: I added the --config=celeryconfig part in CELERYD_OPTS.
我使用
sudo useradd -N -M --system -s /bin/false celery
然后创建组 celery 并将用户添加到其中:
and then created group celery and added user to it:
$ id celery
uid=999(celery) gid=1005(celery) groups=1005(celery)
我将chown celery:celery用于文件夹:
I used chown celery:celery for folders:
/var/run/celery/
/var/log/celery/
当我尝试启动该服务时,没有任何错误提示:
When I try to start the service, I get no indication of error:
$ sudo service celeryd start
celery init v10.0.
Using config script: /etc/default/celeryd
但是状态显示没有找到pids":
but status gives me "no pids were found":
$ sudo service celeryd status
celery init v10.0.
Using config script: /etc/default/celeryd
celeryd is stopped: no pids were found
实际上,ps -ef不会给出结果,也不会创建PID文件或日志文件:
and indeed, ps -ef gives no results and no PID file or log files are created:
$ 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 ../
其他信息:
$ pip freeze | grep celery
celery==3.1.9
我想念什么?我应该在哪里寻找关于celeryd为什么不开始的更多线索?
What am I missing? Where should I be looking for more clues as to why celeryd is not starting?
推荐答案
我复制了您的步骤,并导致了同样的问题.问题是芹菜使用者没有外壳.
I replicated your steps and it resulted in the same issue. The problem was the celery user not having a shell.
sudo useradd -N -M --system -s /bin/false celery
将-s /bin/false
更改为-s /bin/bash
可以解决此问题.原因是celeryd初始化脚本使用celery用户的shell执行celery命令.如果没有外壳,则下面的su命令会静默退出.
Changing -s /bin/false
to -s /bin/bash
fixed the issue. The reason being is that the celeryd init script uses the celery user's shell to execute celery commands. Without a shell, the su command below exits silently.
_chuid () {
su "$CELERYD_USER" -c "$CELERYD_MULTI $*"
}
这篇关于芹菜守护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!