2014-10-28 80 views
2

我有/var/tasks/tasks.py中定義的任務(對於芹菜)。芹菜:自動啓動工作(啓動時)

我有一個virtualenv在/var/tasks/venv應該用於運行/var/tasks/tasks.py

我可以手動啓動工作要處理的任務是這樣的:

cd /var/tasks 
. venv/bin/activate 
celery worker -A tasks -Q queue_1 

現在,我想守護進程這一點。

我從GitHub複製init.d腳本,並正在使用/etc/default/celeryd以下配置文件:

# name(s) of nodes to start 
CELERYD_NODES="worker1" 

# absolute or relative path to celery binary 
CELERY_BIN="/var/tasks/venv/bin/celery" 

# app instance 
CELERY_APP="tasks" 

# change to directory on upstart 
CELERYD_CHDIR="/var/tasks" 

# options 
CELERYD_OPTS="-Q queue_1 --concurrency=8" 

# %N will be replaced with the first part of the nodename. 
CELERYD_LOG_FILE="/var/log/celery/%N.log" 
CELERYD_PID_FILE="/var/run/celery/%N.pid" 

# unprivileged user/group 
CELERYD_USER="celery" 
CELERYD_GROUP="celery" 

# create pid and log directories, if missing 
CELERY_CREATE_DIRS=1 

當我開始(通過init.d腳本)的服務,它說:

celery init v10.1. 
Using config script: /etc/default/celeryd 

但是,它不處理隊列中的任何任務,日誌文件中也沒有任何任務。

我在做什麼錯?

回答

2

Supervisor可能是一個不錯的選擇,但如果你想使用Celery Init.d腳本將建議你從他們的Github Source中複製它。

sudo vim /etc/init.d/celeryd 

將代碼從https://github.com/celery/celery/blob/master/extra/generic-init.d/celeryd複製到文件中。詳情請參閱daemonizing tutorial

sudo chmod 755 /etc/init.d/celeryd 
sudo chown root:root /etc/init.d/celeryd 
sudo nano /etc/default/celeryd 

複製粘貼下面的配置,並相應地改變

#Where your Celery is present 
CELERY_BIN="/home/shivam/Desktop/deploy/bin/celery" 

# App instance to use 
CELERY_APP="app.celery" 

# Where to chdir at start 
CELERYD_CHDIR="/home/shivam/Desktop/Project/demo/" 

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

# 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" 

保存並退出

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

這將自動啓動芹菜上引導

sudo update-rc.d celeryd defaults