我已将 celery 设置为 systemd这里提到。
我的芹菜服务
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=aj
Group=aj
EnvironmentFile=/etc/conf.d/celery
WorkingDirectory=/root/project
ExecStart=/bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} multi start ${CELERY_NODES} \
--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} -A ${CELERY_APP} multi restart ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
[Install]
WantedBy=multi-user.target
我的/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="/usr/local/bin/celery"
CELERY_BIN="/root/venv/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="project"
# 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"
现在,当我通过输入启动 celery 时,sudo service celery start
我收到以下响应
● celery.service - Celery Service
Loaded: loaded (/etc/systemd/system/celery.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Oct 02 07:19:51 ubuntu-s-1vcpu-1gb-blr1-01 sh[30549]: > Starting nodes...
Oct 02 07:19:54 ubuntu-s-1vcpu-1gb-blr1-01 sh[30564]: celery multi v5.0.0 (singularity)
Oct 02 07:19:54 ubuntu-s-1vcpu-1gb-blr1-01 sh[30564]: > w1@ubuntu-s-1vcpu-1gb01: DOWN
Oct 02 07:19:56 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Started Celery Service.
Oct 02 07:22:06 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Starting Celery Service...
Oct 02 07:22:09 ubuntu-s-1vcpu-1gb-blr1-01 sh[30701]: celery multi v5.0.0 (singularity)
Oct 02 07:22:09 ubuntu-s-1vcpu-1gb-blr1-01 sh[30701]: > Starting nodes...
Oct 02 07:22:14 ubuntu-s-1vcpu-1gb-blr1-01 sh[30715]: celery multi v5.0.0 (singularity)
Oct 02 07:22:14 ubuntu-s-1vcpu-1gb-blr1-01 sh[30715]: > w1@ubuntu-s-1vcpu-1gb01: DOWN
Oct 02 07:22:16 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Started Celery Service.
我哪里错了?
ps:我在安装 celery 时遇到了很多问题,认真考虑不使用它,因为它很复杂而且文档没有帮助。我应该使用其他替代方案吗?