Celery Daemon在Centos 7上不起作用

max*_*max 1 python daemon celery systemd centos7

我试图在具有systemd / systemctl的Centos 7上运行celery守护程序。它不起作用。

  • 我尝试了一个非守护程序的案例,它奏效了
  • 我运行了〜mytask,它在客户端计算机和运行celery守护程序的服务器上冻结了,我什么都没有记录。
  • 我注意到实际上没有任何芹菜处理程序正在运行。

有什么建议解决此问题吗?

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

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"
Run Code Online (Sandbox Code Playgroud)

注意:我使用以下命令启动守护进程

sudo /etc/init.d/celeryd start
Run Code Online (Sandbox Code Playgroud)

我从以下网址获得了celery守护程序脚本: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.
Run Code Online (Sandbox Code Playgroud)

Gre*_*cki 5

正如@ChillarAnand之前回答的那样,请不要使用celeryd

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

这是我工作的非显而易见的示例。

它们已经在Centos 7.1.1503上进行了测试,并且celery 3.1.23(Cipater)在a中运行virtualenv,并且来自Celery tutorial中的task.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
Run Code Online (Sandbox Code Playgroud)

运行多名工人

[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
Run Code Online (Sandbox Code Playgroud)

(请注意,我正在使用-c / --concurrency> 1 运行工人,但也可以将其设置为1或默认值。如果您不使用它,它也应该起作用virtualenv,但我强烈建议您使用它。)

我真的不明白为什么systemd在第一种情况下不能猜测分叉进程的PID,以及为什么将pidfile放在特定位置会破坏第二种情况,所以我在这里提交了罚单:https : //github.com/芹菜/芹菜/问题/ 3459。如果我自己得到答案或提出一些解释,那么我将在此处发布。