在后台运行一个 celery worker [英] Run a celery worker in the background
问题描述
我正在像这样运行一个芹菜工人:
I am running a celery worker like this:
celery worker --app=portalmq --logfile=/tmp/portalmq.log --loglevel=INFO -E --pidfile=/tmp/portalmq.pid
现在我想在后台运行这个工人.我尝试了几件事,包括:
Now I want to run this worker in the background. I have tried several things, including:
nohup celery worker --app=portalmq --logfile=/tmp/portal_mq.log --loglevel=INFO -E --pidfile=/tmp/portal_mq.pid >> /tmp/portal_mq.log 2>&1 </dev/null &
但它不起作用.我检查了 celery 文档,发现了这个:
But it is not working. I have checked the celery documentation, and I found this:
特别是这条评论是相关的:
Specially this comment is relevant:
In production you will want to run the worker in the background as a daemon.
To do this you need to use the tools provided by your platform, or something
like supervisord (see Running the worker as a daemon for more information).
这对于在后台运行进程来说开销太大.我需要在我的服务器中安装 supervisord,并熟悉它.暂时不去.有没有一种简单的方式在后台运行 celery worker?
This is too much overhead just to run a process in the background. I would need to install supervisord in my servers, and get familiar with it. No go at the moment. Is there a simple way of running a celery worker in the backrground?
推荐答案
supervisor 非常简单,只需很少的工作即可完成设置,同样适用于 celery 与 supervisor 的组合.
supervisor is really simple and requires really little work to get it setup up, same applies for to celery in combination with supervisor.
设置它应该不会超过 10 分钟 :)
It should not take more than 10 minutes to setup it up :)
使用 apt-get 安装 supervisor
install supervisor with apt-get
创建/etc/supervisor/conf.d/celery.conf 配置文件
create /etc/supervisor/conf.d/celery.conf config file
在 celery.conf 文件中粘贴一些内容
paste somethis in the celery.conf file
[program:celery]
directory = /my_project/
command = /usr/bin/python manage.py celery worker
加上(如果你需要的话)一些可选的和有用的东西(用 dummy值)
plus (if you need) some optional and useful stuff (with dummy values)
user = celery_user
group = celery_group
stdout_logfile = /var/log/celeryd.log
stderr_logfile = /var/log/celeryd.err
autostart = true
environment=PATH="/some/path/",FOO="bar"
重启主管(或者做 supervisorctl reread; supervisorctl add芹菜)
restart supervisor (or do supervisorctl reread; supervisorctl add celery)
之后你会得到很好的 ctl 命令来管理 celery 进程:
after that you get the nice ctl commands to manage the celery process:
supervisorctl start/restart/stop celery
supervisorctl tail [-f] celery [stderr]
这篇关于在后台运行一个 celery worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!