将芹菜工人作为守护程序

时间:2019-04-06 08:00:14

标签: django linux ubuntu celery

我试图将芹菜投入生产。我一直按照这里的说明进行操作:

https://www.linode.com/docs/development/python/task-queue-celery-rabbitmq/#start-the-workers-as-daemons

我目前正在执行步骤7,即“ sudo systemctl start celeryd”。运行此程序时,我被告知celeryd.service失败。我已经运行'journalctl -xe'来查找日志详细信息,我将其复制到下面。

我对celery还是很陌生,所以在解释日志文件以找出问题所在时遇到了困难,因此,我们将不胜感激。如果需要更多信息,请询问,我会尽力提供。

Apr 05 10:44:47 user-admin systemd[6477]: celeryd.service: Failed to determine user credentials: No such process
Apr 05 10:44:47 user-admin systemd[6477]: celeryd.service: Failed at step USER spawning /bin/sh: No such process
-- Subject: Process /bin/sh could not be executed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The process /bin/sh could not be executed and failed.
--
-- The error number returned by this process is 3.
Apr 05 10:44:47 user-admin systemd[1]: celeryd.service: Control process exited, code=exited status=217
Apr 05 10:44:47 user-admin systemd[1]: celeryd.service: Failed with result 'exit-code'.
Apr 05 10:44:47 user-admin systemd[1]: Failed to start Celery Service.
-- Subject: Unit celeryd.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit celeryd.service has failed.
--
-- The result is RESULT.
Apr 05 10:44:47 user-admin sudo[6472]: pam_unix(sudo:session): session closed for user root
Apr 05 10:45:01 user-admin CRON[6481]: pam_unix(cron:session): session opened for user root by (uid=0)
Apr 05 10:45:01 user-admin CRON[6482]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Apr 05 10:45:01 user-admin CRON[6481]: pam_unix(cron:session): session closed for user root
Apr 05 10:45:05 user-admin sudo[6485]: djangoadmin : TTY=pts/1 ; PWD=/var/log/celery ; USER=root ; COMMAND=/bin/journalctl -xe

1 个答案:

答案 0 :(得分:0)

从ExecStart,ExecStop和ExecRestart(在celeryd.service中)中删除/bin/sh -c

假设您在/home/celery/venv中有一个虚拟环境,并且在此环境中安装了Celery,那么您的ExecStart(和其他Exec *行)应如下所示:

ExecStart=/home/celery/venv/bin/celery multi start ${CELERYD_NODES} \
  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} 
  ${CELERYD_OPTS}'

要创建虚拟环境,请执行以下操作:python3 -m venv /home/celery/venv

如果celery用户是在其他路径中创建的,则将上面代码中的/home/celery更改为celery用户的相应“家” ...

更新:如果您使用与Linode页面上相同的配置文件,则可以使用ExecStart=${CELERY_BIN} multi start...