2014-07-09 74 views
7

我有一個Django應用程序中,它具有芹菜功能運行芹菜守護進程,這樣我就可以能夠成功地運行芹菜像下面使用監督員不工作

celery -A tasks worker --loglevel=info 

但作爲一個衆所周知的事實是,我們需要運行它作爲一個守護進程,所以我寫了/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 

內低於celery.conf文件,但是當我嘗試更新像supervisorctl rereadsupervisorctl update監事我是從收到消息

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

不要以root身份運行 - 這不應該是必要的。 (你是否在Django上使用這個功能 - 和那裏的用戶一樣運行。) –

+0

是的,當我刪除行'environment = HOME =「/ root」,USER =「root」時,它工作正常 –

+0

我有這個AWS Elasticbeanstalk存在問題,使用user = ec2-user爲我修復了 –

回答

2

你需要使用非超級用戶帳戶運行芹菜,請刪除以下從你的配置行:

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

而且這些行添加到您的配置,我假設你使用django作爲非超級用戶和developers作爲用戶組:

user=django 
group=developers 

注意,子進程將繼承用於啓動SUPERV的 外殼的環境變量除了這裏覆蓋的 和在程序的環境選項內。見supervisord documents

所以請注意,當您通過supervisor配置文件更改環境變量,變化將不會被運行supervisorctl rereadsupervisorctl reload適用。你應該通過以下命令運行從一開始主管:

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

我有同樣的問題,所以我在我的程序配置添加

environment=C_FORCE_ROOT="yes" 

,但 所以我用它沒有工作

environment=C_FORCE_ROOT="true" 

它的工作

+0

就像一個魅力!謝謝! –

+0

^不安全的解決方法,而不是解決方法。 – Pieter

+0

試過這個導出C_FORCE_ROOT ='true'。還將其添加到bashrc中。即使那樣它不起作用 – Ritesh

1

this other threadØ n stackoverflow。我設法添加以下設置,併爲我工作。

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