关于supervisor的说明及配置文件参数说明和使用方法可以看这篇博客,地址:https://www.cnblogs.com/zhoujinyi/p/6073705.html
说明:我把supervisor和celery配合使用,实现supervisor管理celery进程,在这里我选择rabbitmq作为celery异步任务的中间人。
遇到的问题:supervisor启动报 gave up: 02 entered FATAL state, too many start retries too quickly,排查supervisor管理的celeryworker进程日志,显示错误信息如下:
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).
问题说明:celery不能用root用户启动解决(C_FORCE_ROOT environment)
解决办法:
```
from celery import Celery, platforms
app = Celery('tasks', broker='amqp://myuser:
mypassword@localhost :5672/vhost')
platforms.C_FORCE_ROOT = True #加上这一行
@app.task
def add(x, y):
return x + y
```
另外还有一种解决办法:
在supervisor管理的celeryworker进程的配置文件中可以使用关键字 environment 来添加你需要使用的那个 python 来指定你启动的环境变量。同理可以添加别的环境变量信息。针对当前问题,添加C_FORCE_ROOT="yes"
如下所示:
[program:dnscheckbranch]
command = celery worker -A ncelery -Q xxxx --maxtasksperchild=64 -c 1 -l INFO -n henan-topnode.%(program_name)s.%(process_num)02d -P prefork --workdir=/opt/trunk --uid=root --without-mingle --without-gossip
environment = PYTHONPATH ="/opt/trunk", C_FORCE_ROOT="yes"
directory = /opt/trunk
user = root
process_name = %(process_num)02d
numprocs = 8
stdout_logfile = /var/log/supervisord/xxxx.log
stderr_logfile = /var/log/supervisord/xxxx.log
autostart = false
autorestart = true
startsecs = 3
stopwaitsecs = 10
priority = 777
浙公网安备 33010602011771号