Supervisord、Celery 和 Daemonization - 我的配置是否遵循良好实践?

Supervisord, Celery and Daemonization - Does my configuration respect good practice?

我已经使用 Apache2 部署了一个 Django 应用程序,并且一直在为 Celery 配置而苦苦挣扎。

第一次尝试:

我使用 systemd 进行 celery 的守护进程,celery_beat 如 celery documentation 中所述。它有点像使用这种配置(不建议用于生产)

ExecStart=/path/to/celery/bin/ -A proj worker
ExecStart=/path/to/celery/bin/ -A proj beat

但我无法使“官方”配置正常工作,如下所示:

ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

服务是 运行 但计划任务没有执行。

当前配置:

我读过这个 article(Celery 4 Periodic Tasks on Medium)建议使用 supervisord。我就是这么做的,我的配置文件是这样的

[program:projworker]

command=/path/to/celery/bin/-A proj worker -l info

所以它实际上与 Celery 文档中不建议使用的命令相同。(尽管对于这两种配置我都正确设置了项目目录、用户和组等)。不过一切都很顺利。

最后,我的问题是:这是否真的尊重良好做法?根据这个 piece 的文档 supervisord 处理守护进程,但实际上我不确定我做对了。

一般来说,我建议使用 multi。使用 multi 的原因是 multi 提供了一种语法,允许您优雅地启动、停止或重新启动 celery worker。也就是说,如果您不需要该功能,或者您有一个很好的方法来处理 supervisord 的启动、停止和重新启动而不使用 multi,请继续按照您的方式进行。

Here is the sample recommended configuration for celery beat with supervisord.