django celery守护进程确实有效:它无法创建pid文件

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

我无法初始化mi celeryd和celerybeat服务,我在另一个环境中使用相同的代码(从一开始就配置所有内容),但这里不起作用。我认为这是通过权限,但我无法运行它。请帮我。

这是我在settings.py上的芹菜conf

CELERY_RESULT_BACKEND = ‘djcelery.backends.database:DatabaseBackend’
CELERY_BROKER_URL = ‘amqp://localhost’
CELERY_ACCEPT_CONTENT = [‘json’]
CELERY_TASK_SERIALIZER = ‘json’
CELERY_RESULT_SERIALIZER = ‘json’
CELERYBEAT_SCHEDULER =  ‘djcelery.schedulers.DatabaseScheduler’
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = TIME_ZONE  # ‘America/Lima’
CELERY_BEAT_SCHEDULE= {}

这是我的文件/etc/init.d/celeryd

https://github.com/celery/celery/blob/master/extra/generic-init.d/celeryd 

然后我用

sudo chmod 755 /etc/init.d/celeryd
sudo chown admin1:admin1 /etc/init.d/celeryd

我创建了/ etc / default / celeryd

CELERY_BIN="/home/admin1/Env/tos/bin/celery"

# App instance to use
CELERY_APP="tos"

# Where to chdir at start.
CELERYD_CHDIR="/home/admin1/webapps/tos/"

# 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.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
#   You need to create this user manually (or you can choose
#   a user/group combination that already exists (e.g., nobody).
CELERYD_USER="admin1"
CELERYD_GROUP="admin1"

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

export SECRET_KEY="foobar"

对于celerybeat我在/etc/init.d/celerybeat上创建了一个文件:

https://github.com/celery/celery/blob/master/extra/generic-init.d/celerybeat

并开始这样的服务:

sudo /etc/init.d/celeryd start
sudo /etc/init.d/celerybeat start

我有这个错误:

sudo: imposible resolver el anfitrión SIO
celery init v10.1.
Using config script: /etc/default/celeryd
celery multi v3.1.25 (Cipater)
> Starting nodes...
    > celery@SIO-PRODUCION: OK
ERROR: Pidfile (celery.pid) already exists.
Seems we're already running? (pid: 30198)
/etc/init.d/celeryd: 515: /etc/init.d/celeryd: --pidfile=/var/run/celery/%n.pid: not found

检查时我也得到了它:

sudo C_FAKEFORK=1 sh -x /etc/init.d/celeryd start
some data .....


starting nodes...
ERROR: Pidfile (celery.pid) already exists.
Seems we're already running? (pid: 30198)
    > celery@SIO-PRODUCION: * Child terminated with errorcode 73
FAILED
+ --pidfile=/var/run/celery/%n.pid
/etc/init.d/celeryd: 515: /etc/init.d/celeryd: --pidfile=/var/run/celery/%n.pid: not found
+ --logfile=/var/log/celery/%n%I.log
/etc/init.d/celeryd: 517: /etc/init.d/celeryd: --logfile=/var/log/celery/%n%I.log: not found
+ --loglevel=INFO
/etc/init.d/celeryd: 519: /etc/init.d/celeryd: --loglevel=INFO: not found
+ --app=tos
/etc/init.d/celeryd: 521: /etc/init.d/celeryd: --app=tos: not found
+ --time-limit=300 --concurrency=8
/etc/init.d/celeryd: 523: /etc/init.d/celeryd: --time-limit=300: not found
+ exit 0
celery daemon django-celery celerybeat celeryd
2个回答
1
投票

我有同样的问题,我解决了她:

rm -f /webapps/celery.pid && /etc/init.d/celeryd start

你可以尝试这样做。在运行芹菜之前,通过粘合命令通过&符清理pid文件。


0
投票

其他方式,创建一个django命令

import shlex
import subprocess

from django.core.management.base import BaseCommand


class Command(BaseCommand):
    def handle(self, *args, **options):
        kill_worker_cmd = 'pkill -9 celery'
        subprocess.call(shlex.split(kill_worker_cmd))

在开始之前调用它,或者只是

pkill -9 celery
© www.soinside.com 2019 - 2024. All rights reserved.