首页 > 解决方案 > 芹菜不作为守护进程工作

问题描述

我正在尝试使用 django 和 celery 来自动执行任务,并希望将 celery 作为守护进程运行。我从其官方文档中复制了 celeryd 和 celerybeat 的代码,并将其放在 /etc/init.d/ 文件夹中。

下面是我的 celeryd 文件的代码,我把它放在“etc/default”文件夹中。加粗字母的代码是注释代码。

CELERY_BIN="/home/user/.local/bin/celery"

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

# Where to chdir at start.
CELERYD_CHDIR="/home/user/django_project"

CELERY_APP="django_project"

#How to call "manage.py celeryd_multi"
#CELERYD_MULTI="$CELERYD_CHDIR/django_project/manage.py celeryd_multi"

# Extra arguments to celeryd
#CELERYD_OPTS="--time-limit 300 --concurrency=8"

# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"

# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
CELERYD_USER="user"
CELERYD_GROUP="user"

# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="settings"


# beat settings

CELERYBEAT_OPTS="--scheduler django_celery_beat.schedulers:DatabaseScheduler"

CELERYBEAT_LOG_FILE="/var/log/celery/celeryBeat.log"
CELERYBEAT_PID_FILE="/var/run/celery/celeryBeat.pid"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

我使用“sudo /etc/init.d/celeryd/start”命令启动了 celeryd。

我使用“sudo /etc/init.d/celerybeat/start”命令启动了 celerybeat。

当我检查 celery 和 celerybeat 的状态时,它显示

    celery init v10.1.
Using config script: /etc/default/celeryd
celeryd down: no pidfiles found

请让我知道如何将芹菜作为守护进程运行。

标签: djangopython-3.xcelerybeatceleryd

解决方案


推荐阅读