Answer the question
In order to leave comments, you need to log in
Daemon in celery for django: how to configure?
I am using Celery 4, Django 1.11, Python 3.5. I met Celery quite recently, just yesterday I was able to launch the first task with the worker manually enabled.
There was a problem configuring the daemon.
Opened the documentation:
docs.celeryproject.org/en/latest/userguide/daemonizing.html
Chose the option with celeryd, moved this file:
https://github.com/celery/celery/tree/3.1/extra/ge...
to folder etc/init.d/ without changes.
I created a celeryd file and added the text specified in the documentation as a test configuration, and moved it to etc/default/.
And then I don't understand anything. I will try everything in order.
1. What should the default setting look like?
Now I have this:
CELERYD_NODES="irr_parser"
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
CELERY_APP="irr_parser"
CELERYD_CHDIR="/opt/Myproject/"
CELERYD_OPTS="--time-limit=300 --concurrency=8"
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="celery"
CELERYD_GROUP="celery"
CELERY_CREATE_DIRS=1
Answer the question
In order to leave comments, you need to log in
First of all, I want to draw your attention to this:
If you "choose" between celeryd or celerybeat, then the choice is meaningless: celeryd is a daemon for executing tasks, celerybeat monitors the schedule of tasks, sending them at a given time for execution. So, if you have a need to run tasks on a schedule, you need to configure both daemons.
Now some answers to questions.
This is an instance of the celery.Celery class, here is the path to it and you need to register it, in the format package[.subpackages].module:variable
. For example, I have a project/celery.py file that creates an instance like this:
from celery import Celery
app = Celery('project')
project.celery:app
CELERY_BIN="/usr/local/bin/celery"
Went along the path, didn't see any celery there.
/home/webapp/Env/project-backend-3.5/bin/celery
CELERYD_SU_ARGS="-l"
What is this? Why is this?
[Unit]
Description=Celery Service
After=network.target redis.target
[Service]
Type=forking
User=webapp
Group=webapp
EnvironmentFile=-/etc/systemd/celery.conf
WorkingDirectory=/home/webapp/project_dir/project/src
PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p ${CELERYD_STATE_DIR}
ExecStartPre=/bin/chown -R ${CELERYD_USER}:${CELERYD_GROUP} ${CELERYD_STATE_DIR}
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
[Unit]
Description=CeleryBeat Service
After=network.target redis.target rabbitmq.target
[Service]
Type=simple
User=webapp
Group=webapp
EnvironmentFile=-/etc/systemd/celery.conf
WorkingDirectory=/home/webapp/project_dir/project/src
PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p ${CELERYBEAT_STATE_DIR}
ExecStartPre=/bin/chown -R ${CELERYD_USER}:${CELERYD_GROUP} ${CELERYBEAT_STATE_DIR}
ExecStartPre=/bin/rm ${CELERYBEAT_SCHEDULE}
ExecStart=/bin/bash -c '${CELERY_BIN} beat \
-A ${CELERY_APP} \
--workdir=${CELERYBEAT_WORKDIR} \
--pidfile=${CELERYBEAT_PID_FILE} \
--logfile=${CELERYBEAT_LOG_FILE} \
--loglevel=${CELERYBEAT_LOG_LEVEL} \
--schedule=${CELERYBEAT_SCHEDULE}'
ExecStop=/bin/systemctl kill celerybeat.service
[Install]
WantedBy=multi-user.target
# See
# http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#available-options
# Common Celery Settings
CELERY_BIN="/home/webapp/Env/project-backend-3.5/bin/celery"
CELERYD_USER="webapp"
CELERYD_GROUP="webapp"
CELERY_APP="project.celery:app"
# Common env settings
DJANGO_SETTINGS_MODULE=settings.production
LC_ALL=ru_RU.UTF-8
LC_LANG="ru_RU.UTF-8"
LANG=ru_RU.UTF-8
# Worker settings
CELERYD_NODES="w1 w2 w3 w4 w5 w6"
CELERYD_OPTS="-Q:w1 default --autoscale:w1=8,4 \
-Q:w2 queue2 --autoscale:w2=6,2 \
-Q:w3 queue3 --autoscale:w3=8,2 \
....................
-Q:w6 queue6 --autoscale:w6=6,2 "
CELERYD_MULTI="multi"
CELERYD_STATE_DIR="/var/run/celery"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_LOG_LEVEL="INFO"
# Beat settings
CELERYBEAT_STATE_DIR="/var/run/celerybeat"
CELERYBEAT_PID_FILE="/var/run/celerybeat/beat.pid"
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"
CELERYBEAT_LOG_LEVEL="INFO"
CELERYBEAT_SCHEDULE="/var/run/celerybeat/schedule"
CELERYBEAT_WORKDIR="/home/webapp/project_dir/project/src"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question