gpt4 book ai didi

django - 将 celery worker 作为守护进程启动

转载 作者:太空宇宙 更新时间:2023-11-04 11:52:47 25 4
gpt4 key购买 nike

我正在尝试将 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

最佳答案

从 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用户合适的“home”...

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

关于django - 将 celery worker 作为守护进程启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55547056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com