9

我有一个 django 应用程序,它具有 celery 功能,所以我可以像下面那样成功运行 celery

celery -A tasks worker --loglevel=info

但众所周知,我们需要将它作为守护进程运行,所以我在文件夹中编写了以下celery.conf文件/etc/supervisor/conf.d/

; ==================================
;  celery worker supervisor example
; ==================================

[program:celery]
; Set full path to celery program if using virtualenv
command=/root/Envs/proj/bin/celery -A app.tasks worker --loglevel=info

user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"
directory=/root/apps/proj/structure
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

但是当我尝试更新主管时supervisorctl rereadsupervisorctl update我收到了来自supervisorctl status

celery                           FATAL      Exited too quickly (process log may have details)

所以我去worker.log归档并看到如下错误消息

Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!

If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).

User information: uid=0 euid=0 gid=0 egid=0

C_FORCE_ROOT那么为什么即使我们在主管配置文件中将它设置为环境变量,它也会抱怨 呢?我在上面的 conf 文件中做错了什么?

4

3 回答 3

3

我有同样的问题,所以我添加了

environment=C_FORCE_ROOT="yes" 

在我的程序配置中,但它没有用,所以我使用了

environment=C_FORCE_ROOT="true"

它正在工作

于 2015-11-27T02:18:52.323 回答
2

来自stackoverflow上的另一个线程。我设法添加了以下设置,它对我有用。

app.conf.update(
    CELERY_ACCEPT_CONTENT = ['json'],
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_RESULT_SERIALIZER = 'json',
)
于 2018-02-13T04:52:23.647 回答
2

您需要使用非超级用户帐户运行 celery,请从您的配置中删除以下行:

user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"

并将这些行添加到您的配置中,我假设您django用作非超级用户和developers用户组:

user=django
group=developers

请注意,子进程将继承用于启动 supervisord 的 shell 的环境变量,除了这里和程序的 environment 选项中覆盖的那些。见监督文件

所以请注意,当您通过supervisor配置文件更改环境变量时,更改不会通过运行supervisorctl rereadand应用supervisorctl reload。您应该通过以下命令从一开始就运行主管:

supervisord -c /path/to/config/file.conf
于 2015-11-22T12:32:51.253 回答