芹菜守护程序在CentOS 7上不起作用



我正在尝试在具有SystemD/SystemCtl的CentOS 7上运行芹菜守护程序。它不起作用。

  • 我尝试了一个非daemon案,它起作用
  • 我运行了〜mytask,并且在客户端计算机和芹菜守护程序正在运行的服务器上冻结了,我绝对没有记录。
  • 我注意到实际上没有芹菜过程正在运行。

如何解决此问题?

这是我的守护程序默认配置:

CELERYD_NODES="localhost.localdomain"
CELERY_BIN="/tmp/myapp/venv/bin/celery"
CELERY_APP="pipeline"
CELERYD_OPTS="--broker=amqp://192.168.168.111/"
CELERYD_LOG_LEVEL="INFO"
CELERYD_CHDIR="/tmp/myapp"
CELERYD_USER="root"

注意:我正在用

开始守护程序
sudo /etc/init.d/celeryd start

,我从以下方式获得了我的芹菜守护程序脚本:https://raw.githubusercontent.com/celery/celery/3.1/extra/generic-init.d/celeryd

我还尝试了一个:https://raw.githubusercontent.com/celery/celery/3.1/extra/generic-init.d/celeryd但这向我展示了试图启动守护程序时的错误:

systemd[1]: Starting LSB: celery task worker daemon...
celeryd[19924]: basename: missing operand
celeryd[19924]: Try 'basename --help' for more information.
celeryd[19924]: Starting : /etc/rc.d/init.d/celeryd: line 193: multi: command not found
celeryd[19924]: [FAILED]
systemd[1]: celeryd.service: control process exited, code=exited status=1
systemd[1]: Failed to start LSB: celery task worker daemon.
systemd[1]: Unit celeryd.service entered failed state.

正如@chillaranand之前回答的那样,请勿使用celeryd

但实际上并不像他写的那样简单,用 celery multi和systemd进行芹菜。

这是我的工作,不太明显的(我认为)示例。

它们已在 CentOS 7.1.1503 上进行了测试,并带有芹菜3.1.23 (cipater)在virtualenv中运行的tasks.py示例应用程序,来自芹菜教程。

运行一个工人

[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=vagrant
Group=vagrant
# directory with tasks.py
WorkingDirectory=/home/vagrant/celery_example
# !!! using the below systemd is REQUIRED in this case!
# (you will still get a warning "PID file /var/run/celery/single.pid not readable (yet?) after start." from systemd but service will in fact be starting, stopping and restarting properly. I haven't found a way to get rid of this warning.)
PIDFile=/var/run/celery/single.pid
# !!! using --pidfile option here and below is REQUIRED in this case!
# !!! also: don't use "%n" in pidfile or logfile paths - you will get these files named after the systemd service instead of after the worker (?)
ExecStart=/home/vagrant/celery_example/venv/bin/celery multi start single-worker -A tasks --pidfile=/var/run/celery/single.pid --logfile=/var/log/celery/single.log "-c 4 -Q celery -l INFO"
ExecStop=/home/vagrant/celery_example/venv/bin/celery multi stopwait single-worker --pidfile=/var/run/celery/single.pid --logfile=/var/log/celery/single.log
ExecReload=/home/vagrant/celery_example/venv/bin/celery multi restart single-worker --pidfile=/var/run/celery/single.pid --logfile=/var/log/celery/single.log
# Creates /var/run/celery, if it doesn't exist
RuntimeDirectory=celery
[Install]
WantedBy=multi-user.target

运行多个工人

[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=vagrant
Group=vagrant
# directory with tasks.py
WorkingDirectory=/home/vagrant/celery_example
# !!! in this case DON'T set PIDFile or use --pidfile or --logfile below or it won't work!
ExecStart=/home/vagrant/celery_example/venv/bin/celery multi start 3 -A tasks "-c 4 -Q celery -l INFO"
ExecStop=/home/vagrant/celery_example/venv/bin/celery multi stopwait 3
ExecReload=/home/vagrant/celery_example/venv/bin/celery multi restart 3
# Creates /var/run/celery, if it doesn't exist
RuntimeDirectory=celery
[Install]
WantedBy=multi-user.target

(请注意,我正在使用-c / --concurrency> 1运行工人,但它也可以将其设置为1或默认值。如果您不使用virtualenv,这也可以工作,但我强烈建议您使用它。)p>我真的不明白为什么Systemd在第一种情况下无法猜测分叉过程的PID,以及为什么将pidfiles放在特定位置会破坏第二种情况,所以我在这里提交了票:https://github.com/芹菜/芹菜/问题/3459。如果我会得到答案或自己提出一些解释,那么我将在这里发布它们。

celeryd被称为。如果您能够在非daemon模式下运行

celery worker -l info -A my_app -n my_worker

您可以简单地使用芹菜多

来道座
celery multi my_worker -A my_app -l info

话虽如此,如果您仍然想使用celeryd,请尝试以下步骤。

相关内容

  • 没有找到相关文章

最新更新