Django 使用supervisor作为守护进程运行芹菜不起作用
我有一个django应用程序,其中有芹菜功能,所以我可以像下面这样成功地运行芹菜Django 使用supervisor作为守护进程运行芹菜不起作用,django,celery,supervisord,celery-task,Django,Celery,Supervisord,Celery Task,我有一个django应用程序,其中有芹菜功能,所以我可以像下面这样成功地运行芹菜 celery -A tasks worker --loglevel=info 但众所周知,我们需要将其作为守护进程运行,因此我在/etc/supervisor/conf.d/文件夹中编写了下面的芹菜.conf文件 ; ================================== ; celery worker supervisor example ; ==========================
celery -A tasks worker --loglevel=info
但众所周知,我们需要将其作为守护进程运行,因此我在/etc/supervisor/conf.d/
文件夹中编写了下面的芹菜.conf
文件
; ==================================
; 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 reread
和supervisorctl 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\u FORCE\u ROOT
,即使我们在supervisor conf文件中将其设置为环境变量?上面的conf文件中我做错了什么?您需要使用非超级用户帐户运行芹菜,请从配置中删除以下行:
user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"
如果将这些行添加到配置中,我假设您使用django
作为非超级用户,使用developers
作为用户组:
user=django
group=developers
请注意,子流程将继承
shell用于启动supervisord,此处重写的除外
并且在程序的环境选项中。看
因此,请注意,当您通过supervisor
配置文件更改环境变量时,运行supervisorctl-reread
和supervisorctl-reload
将不会应用更改。您应该通过以下命令从一开始就运行supervisor:
supervisord -c /path/to/config/file.conf
我也有同样的问题,所以我补充道
environment=C_FORCE_ROOT="yes"
在我的程序配置中,但它不起作用
所以我用
environment=C_FORCE_ROOT="true"
它从stackoverflow开始工作。我成功地添加了以下设置,这对我很有用
app.conf.update(
CELERY_ACCEPT_CONTENT = ['json'],
CELERY_TASK_SERIALIZER = 'json',
CELERY_RESULT_SERIALIZER = 'json',
)
不要以root用户身份运行-这应该不是必需的。(你是在Django中使用它吗?以与那里相同的用户身份运行。)是的,当我删除行
environment=HOME=“/root”,user=“root”
时,它工作正常。我在AWS Elasticbeanstalk中遇到了这个问题,使用user=ec2用户修复了它,用于度量此导出C_FORCE_root='true'。还将此添加到bashrc中。即使这样,它也不起作用