0

I can't init mi celeryd and celerybeat service, I used the same code on another enviroment (configuring everything from the start) but here don't work. I think this was by permissions but I could'nt run it. please help me.

this is my celery conf on settings.py

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= {}

this is my file /etc/init.d/celeryd

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

then I use

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

and I created /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"

for celerybeat I create a file on /etc/init.d/celerybeat with:

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

and start service like this:

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

and I have this error:

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

I also I got it when check it with :

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
1
  • From your logs it is not clear if pid file already exists or if '%n' is not replaced with your node name. You can always try to start celery like this and play with options: 'python -m celery worker -A your_celery_app_name --pidfile=/tmp/test.pid --uid=<uid of your admin user> --gid=<gid of your admin user>' (check python -m celery worker --help for options.
    – Greg0ry
    Feb 16, 2018 at 23:21

2 Answers 2

1

I have the same problem and i resolved her so:

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

You can try do this. Before running celery clean up pid-files through ampersand by gluing commands.

0

Other way, create a django command

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))

Call it before you start, or just

pkill -9 celery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.