2013-06-03 51 views
2

我試圖daemonize在virtualenv內運行的django的芹菜過程。我從https://github.com/celery/celery/tree/master/extra/generic-init.d複製celeryd文件/etc/init.d/中daemonizing芹菜過程芹菜多沒有找到

我然後在http://ask.github.io/celery/cookbook/daemonizing.html#example-django-configuration-using-virtualenv創建了內容的配置文件並將其保存爲在/ etc /默認/ celeryd

這是我的/ etc /默認/ celeryd:

# Name of nodes to start, here we have a single node 
CELERYD_NODES="w1" 
# or we could have three nodes: 
#CELERYD_NODES="w1 w2 w3" 

# Where to chdir at start. 
CELERYD_CHDIR="/home/manu/location/to/project/" 

# Python interpreter from environment. 
ENV_PYTHON="/home/manu/.virtualenvs/project_env/bin/python" 

# How to call "manage.py celeryd_multi" 
CELERYD_MULTI= "$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi" 

# How to call "manage.py celeryctl" 
CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl" 

# Extra arguments to celeryd 
CELERYD_OPTS="--verbose --fake --time-limit=300 --concurrency=8" 

# Name of the celery config module. 
CELERY_CONFIG_MODULE="celeryconfig" 

# %n will be replaced with the nodename. 
CELERYD_LOG_FILE="/var/log/celery/%n.log" 
CELERYD_PID_FILE="/var/run/celery/%n.pid" 

# Workers should run as an unprivileged user. 
CELERYD_USER="celery" 
CELERYD_GROUP="celery" 

# Name of the projects settings module. 
export DJANGO_SETTINGS_MODULE="project.settings.production" 

當我運行:

sudo sh -x /etc/init.d/celeryd start 

它失敗,出現以下錯誤:

celeryd-multi start w1 --uid=celery --gid=celery --workdir=/home/manu/location/to/project/ --pidfile=/var/run/celery/%n.pid --logfile=/var/log/celery/%n.log --loglevel=INFO --cmd=-m celery.bin.celeryd_detach --verbose --fake --time-limit=300 --concurrency=8 /etc/init.d/celeryd: 140: /etc/init.d/celeryd: celeryd-multi: not found

我可以看到,它無法找到celeryd_multi。奇怪的是,運行

/path/to/project_env/bin/python /path/to/manage.py celeryd_multi

顯示芹菜多可用。

[更新 - 修正與@Daniel羅斯曼的輸入我起動命令]

現在,當我運行:

sh -x /etc/init.d/celeryd start

這是輸出我看到:

/path/to/.virtualenvs/virtenv/bin/python /path/to/project//manage.py celeryd_detach --time-limit=300 --concurrency=8 --gid=celery --broker=amqp://:@localhost:5672// -n w1.ubuntu-12-10 --logfile=/var/log/celery/w1.log --loglevel=INFO --uid=celery --pidfile=/var/run/celery/w1.pid --workdir=/path/to/project/

OK

+ sleep 5

+ exit 0

我在這裏錯過了什麼?請幫忙!

回答

2

當您執行使用sudo sh命令,你開始一個全新的shell環境。在該環境中,您的virtualenv未激活,並且virtualenv的bin目錄不在路徑上,這可能是爲什麼找不到可執行文件。

如果你真的需要運行這個作爲超級用戶,您應該創建一個執行sudo調用內部的virtualenv包裝腳本。

+0

非常感謝這個輸入!我本人不會想到這一點。這應該讓我更接近解決方案。 – manu

3

你的init.d腳本引用了系統python包,而不是virtualenv python。所以當你在裏面運行芹菜時,你正在引用系統站點包中安裝的那個。

調用芹菜之前添加到的virtualenv的python路徑的引用,一切都應該工作得很好。

話雖這麼說,它通常是更好地使用的init.d到supervisord運行,然後有supervisord旋轉起來的所有其他進程如芹菜和Web應用程序。

+0

正如@丹尼爾羅斯曼所說的,我嘗試了沒有sudo盈餘的命令。現在它似乎啓動了一些節點,但後來在'ps aux |中看不到任何芹菜進程grep芹菜' – manu