将芹菜设置为守护进程时出现问题

Problem setting up celery as a daemon service

三天来,我一直在尝试将 celery 设置为守护进程,但我仍在为此苦苦挣扎。每次启动服务查看状态都是这样,

文档有Type=forking,使用时,服务启动失败。状态显示,

● celery.service - Celery Service
     Loaded: loaded (/etc/systemd/system/celery.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2020-07-23 05:36:18 UTC; 7s ago
    Process: 4256 ExecStart=/bin/sh -c ${CELERY_BIN} multi start ${CELERYD_NODES}    -A ${CELERY_APP} --pidfile=${CELER>
   Main PID: 4272 (code=exited, status=1/FAILURE)

... systemd[1]: Starting Celery Service...
... sh[4257]: celery multi v4.4.6 (cliffs)
... sh[4257]: > Starting nodes...
... sh[4257]:         > w1@dexter-server: OK
... systemd[1]: Started Celery Service.
... systemd[1]: celery.service: Main process exited, code=exited, status=1/FAILURE
... systemd[1]: celery.service: Failed with result 'exit-code'.

日志中没有任何内容。当我删除 Type 时,我得到这个

● celery.service - Celery Service
     Loaded: loaded (/etc/systemd/system/celery.service; disabled; vendor preset: enabled)
     Active: inactive (dead)

... systemd[1]: Started Celery Service.
... sh[2683]: celery multi v4.4.6 (cliffs)
... sh[2683]: > Starting nodes...
... sh[2683]:         > w1@dexter-server: OK
... sh[2690]: celery multi v4.4.6 (cliffs)
... sh[2690]: > w1@dexter-server: DOWN
... systemd[1]: celery.service: Succeeded.

日志中也没有任何内容。这是我当前的文件。

/etc/systemd/system/celery.服务

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

[Service]
User=dexter
Group=dexter
RuntimeDirectory=celery
RuntimeDirectoryMode=0755
EnvironmentFile=/etc/conf.d/celery
WorkingDirectory=/var/www/example.com/myapp
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}'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
  --pidfile=${CELERYD_PID_FILE}'
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]
WantedBy=multi-user.target

/etc/tmpfiles.d/celery.conf

d /var/run/celery 0755 dexter dexter -
d /var/log/celery 0755 dexter dexter -

/etc/conf.d/celery

# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/var/www/example.com/venv/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="myapp.celery:app"
# or fully qualified:
#CELERY_APP="proj.tasks:app"

# How to call manage.py
CELERYD_MULTI="multi"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# - %n will be replaced with the first part of the nodename.
# - %I will be replaced with the current child process index
#   and is important when using the prefork pool to avoid race conditions.
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"

# you may wish to add these options for Celery Beat
CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"

CELERY_CREATE_DIRS=1

我不知道如何配置超出此范围或此时在哪里查找错误。有人可以帮我找出问题并解决这个问题吗?我对分叉等概念有非常基本的了解,所以请放轻松。

我通过将 celery.service 中的块替换为以下内容解决了这个问题。

ExecStart='${CELERY_BIN} ${CELERy_NODES} \
  -A ${CELERY_APP} worker --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
ExecStop='${CELERY_BIN} stopwait ${CELERYD_NODES} \
  --pidfile=${CELERYD_PID_FILE}'
ExecReload='${CELERY_BIN} restart ${CELERYD_NODES} \
  -A ${CELERY_APP} worker --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

我从#celery IRC 得到了帮助。