将 celery 设置为守护进程服务时出现问题

问题描述 投票:0回答:2

我已经尝试将芹菜设置为守护进程三天了,但我仍然在努力解决这个问题。每次我启动服务并检查状态时,都会显示此信息,

文档有

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.service

[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

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

linux celery daemon systemd
2个回答
3
投票

我通过用以下内容替换

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 获得了帮助。


0
投票

就我而言,问题是我的 django 项目的

.env
中的一些额外引号。

systemctl status celery
journalctl -xeu celery
没有记录这个问题。

为了弄清楚这一点,我必须切换到运行 celery 的用户。

su celeryuser

并手动运行命令来启动celery。

celery -A myceleryapp worker --loglevel=info

直到那时我才看到一个

KeyError(f'No such transport: {transport}')
错误,这让我发现我的
BROKER_URL
文件的
.env
变量配置错误。

© www.soinside.com 2019 - 2024. All rights reserved.