使用主管运行芹菜作为守护程序不起作用

时间:2014-07-09 09:48:00

标签: django celery supervisord supervisor celery-task

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

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文件中的环境变量?我在上面的conf文件中做错了什么?

3 个答案:

答案 0 :(得分:2)

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

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

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

user=django
group=developers
  

请注意,子进程将继承环境变量   shell用来启动supervisord,除了在这里重写的那些   并在程序的环境选项中。请参阅supervisord documents

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

supervisord -c /path/to/config/file.conf

答案 1 :(得分:2)

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

environment=C_FORCE_ROOT="yes" 

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

environment=C_FORCE_ROOT="true"

它正在运作

答案 2 :(得分:1)

来自stackoverflow上的this other thread。我设法添加了以下设置,它对我有用。

app.conf.update(
    CELERY_ACCEPT_CONTENT = ['json'],
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_RESULT_SERIALIZER = 'json',
)