通过 systemd 启动 celery 守护进程

通过 systemd 启动 celery 守护进程

在 /usr/lib/systemd/system/celery.service 中:

[Unit]
Description=Celery Nodes Daemon
After=network.target

[Service]
Type=forking
PIDFile=/var/run/celery/main.pid
ExecStart=/usr/bin/python2 /home/myuser/path/to/Django/myproject/manage.py celeryd_multi start w1 --pidfile="/var/run/celery/%n.pid" --logfile="/var/log/celery/%n.log" --cmd="-m celery.bin.celeryd_detach"
ExecStop=/usr/bin/python2 /home/myuser/path/to/Django/myproject/manage.py celeryd_multi stopwait w1 --pidfile="/var/run/celery/%n.pid"

[Install]
WantedBy=multi-user.target

在 shell 中:

$ sudo systemctl enable celery.service
ln -s '/usr/lib/systemd/system/celery.service' '/etc/systemd/system/multi-user.target.wants/celery.service'
$ sudo systemctl start celery.service
Job for celery.service failed. See 'systemctl status celery.service' and 'journalctl -xn' for details.
$ sudo systemctl status celery.service
celery.service - Celery Nodes Daemon
  Loaded: loaded (/usr/lib/systemd/system/celery.service; enabled)
  Active: failed (Result: exit-code) since Пт 2013-03-29 13:22:24 NOVT; 38s ago
  Process: 32273 ExecStart=/usr/bin/python2 /home/anarchist/Desktop/Develop/Django/myproject/manage.py celeryd_multi start w1 --pidfile="/var/run/celery/%n.pid" --logfile="/var/log/celery/%n.log" --cmd="-m celery.bin.celeryd_detach" (code=exited, status=1/FAILURE)

journalctl -xn 中没有关于 celery 的任何信息。如何通过 systemd 启动 celery 守护进程?

答案1

经过大量的实验后,我提出了该服务的配置(已修改以符合您的示例):

[Unit]
Description=Celery Server
After=network.target

[Service]
Type=oneshot
KillMode=control-group
RemainAfterExit=yes
Restart=no
ExecStart=/usr/bin/python2 /home/myuser/path/to/Django/myproject/manage.py celeryd_multi start w1 --pidfile="/tmp/%n.pid" --logfile="/var/log/celery/%n.log" --loglevel=INFO --time-limit=300
ExecStop=/usr/bin/python2 /home/myuser/path/to/Django/myproject/manage.py celeryd_multi stopwait w1 --pidfile="/tmp/%n.pid"

[Install]
WantedBy=multi-user.target

相关内容