Score:0

Failed to start Celery Service

us flag

I am trying to daemonize celery on Linux. And after ironing out a lot of errors and reading through tons of configuration. I am unable to run Celery. I am running Ubuntu 20.04 and Celery 5.2+. Following is the error I get:

● celery.service - Celery Service
     Loaded: loaded (/etc/systemd/system/celery.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2022-01-01 22:16:17 UTC; 22s ago
    Process: 15402 ExecStart=/usr/local/bin/pipenv run celery multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD>
    Process: 15409 ExecStop=/usr/local/bin/pipenv run celery ${CELERY_BIN} multi stopwait ${CELERYD_NODES} --pidfile=${CELERYD_PID_FILE} (code=exited, status=2)

Jan 01 22:16:16 ip-172-31-37-240 pipenv[15409]:   warnings.warn(
Jan 01 22:16:16 ip-172-31-37-240 pipenv[15409]: /usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.23ubuntu1 is an invalid version and will not be supported>
Jan 01 22:16:16 ip-172-31-37-240 pipenv[15409]:   warnings.warn(
Jan 01 22:16:16 ip-172-31-37-240 pipenv[15409]: Loading .env environment variables...
Jan 01 22:16:17 ip-172-31-37-240 pipenv[15409]: Usage: celery [OPTIONS] COMMAND [ARGS]...
Jan 01 22:16:17 ip-172-31-37-240 pipenv[15409]: Try 'celery --help' for help.
Jan 01 22:16:17 ip-172-31-37-240 pipenv[15409]: Error: No such command '/usr/local/bin/celery'.
Jan 01 22:16:17 ip-172-31-37-240 systemd[1]: celery.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Jan 01 22:16:17 ip-172-31-37-240 systemd[1]: celery.service: Failed with result 'exit-code'.
Jan 01 22:16:17 ip-172-31-37-240 systemd[1]: Failed to start Celery Service.

I am a terminal noob but to my understanding when I cd /usr/local/bin/ and then ls -a. I get the following file structure.

.  ..  autopep8  celery  django-admin  gunicorn  markdown_py  pipenv  pipenv-resolver  pycodestyle  sqlformat  virtualenv  virtualenv-clone
#celery.service

[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=celery
Group=celery

EnvironmentFile=/etc/default/celeryd
WorkingDirectory=/home/ubuntu/project/Instagram-Clone-Backend
ExecStart=/usr/local/bin/pipenv run celery multi start ${CELERYD_NODES} \
  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
ExecStop=/usr/local/bin/pipenv run celery ${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
  --pidfile=${CELERYD_PID_FILE}
ExecReload=/usr/local/bin/pipenv run celery ${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
#/etc/default/celeryd

 # Names of nodes to start
 #   most people will only start one node:
 CELERYD_NODES="worker1"
 #   but you can also start multiple and configure settings
 #   for each in CELERYD_OPTS
 #CELERYD_NODES="worker1 worker2 worker3"
 #   alternatively, you can specify the number of nodes to start:
 #CELERYD_NODES=10

 # Absolute or relative path to the 'celery' command:
 #CELERY_BIN="/usr/local/bin/celery"
 #CELERY_BIN="/virtualenvs/def/bin/celery"
 CELERY_BIN="/usr/local/bin/celery"

 # App instance to use
 # comment out this line if you don't use an app
 CELERY_APP="instagram.celery"
 # or fully qualified:
#  CELERY_APP="authentication.tasks:app"

 # Where to chdir at start.
 CELERYD_CHDIR="/home/ubuntu/project/Instagram-Clone-Backend"

 # Extra command-line arguments to the worker
 CELERYD_OPTS="--time-limit=300 --concurrency=8"
 # Configure node-specific settings by appending node name to arguments:
 #CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"

 # Set logging level to DEBUG
 #CELERYD_LOG_LEVEL="DEBUG"

 # %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="celery"
 CELERYD_GROUP="celery"

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

in flag
How did you install `celery`? `pipenv` will only know about it if you used the pip provided by pipenv to install it
GuruRandapa avatar
us flag
@matigo Thank You for your reply... The issue is resolved now. I just wrote my own ExecStart and ExecStop. I figured out that these are just commands that daemon use like `sudo service celery start` will use ExecStart so I just wrote what I normally write to start celery. `pipenv run celery -A instagram.celery worker -l INFO` and it works like a charm.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.