Run CELERY as Daemon in Ubuntu

六月ゝ 毕业季﹏ 提交于 2021-02-07 18:11:16

问题


How to run celery as Daemon service in ubuntu instead of running "celery -A projname worker -l info" command each time.

I am using celery 3.1.8 version....


回答1:


You can make celery into a daemon with the init.d script from celery's repo (Save it to /etc/init.d/). You will also need to create a configuration file for the script to load in /etc/default/celeryd.

Here's the full celery doc.




回答2:


You can make celery worker as a daemon using a tool called supervisord.

It's a simple process manager, you can find an example here on how to configure your worker using supevisor's config file.




回答3:


It is a question asked a long time ago, but I think it is worth to give an answer.

You can follow bellow steps:

  1. Create a celery user
sudo adduser celery
  1. Create the init script
sudo nano celeryd

And copy the celeryd and past to the created celeryd. and then

chmod +x celeryd
sudo mv celeryd /etc/init.d/
  1. Create a configuration file
  • Create the empty /etc/default/celeryd configuration file for the init script
sudo touch /etc/default/celeryd
sudo vim /etc/default/celeryd
  • Edit the above celeryd according to your project.
 # 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="/opt/django_projects/your_proj/your_env/bin/celery"

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

 # Where to chdir at start.
 CELERYD_CHDIR="/opt/django_projects/your_proj/"

 # 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
  1. Create logs directory
sudo mkdir /var/log/celery
sudo chown -R celery: /var/log/celery
  1. Verbose the init-scripts
sudo sh -x /etc/init.d/celeryd start
  1. Enable the daemon
sudo update-rc.d celeryd defaults
sudo service celeryd start

Well, I hope it will be helpful for you. Thank you.



来源:https://stackoverflow.com/questions/22525818/run-celery-as-daemon-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!