2012年7月2日

將celery做成daemon在背景執行

Ubuntu 12.04
celery 2.5.5
celery-with-redis 2.5

以最簡單的單機執行為範例
參考官方文件
首先是執行檔 參考generic-init.d/celeryd
sudo curl https://raw.github.com/ask/celery/master/contrib/generic-init.d/celeryd > celeryd sudo chmod +x celeryd sudo chown root:root celeryd sudo mv celeryd /etc/init.d/celeryd
設定檔
vi 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="/path/to/my/project/" # Extra arguments to celeryd CELERYD_OPTS="--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" sudo chown root:root celeryd sudo mv celeryd /etc/default/celeryd
建立log和pid directory
sudo mkdir /var/log/celery sudo mkdir /var/run/celery
設定開機執行,然後執行
sudo update-rc.d celeryd defaults sudo service celeryd start
順帶ㄧ提,如果要移除開機執行的話
sudo update-rc.d -f celeryd remove service --status-all
也可以使用supervisor來做管理,使用方法是在supervisord.conf中帶進celeryd.conf
所有要被supervisor管理的process都使用類似的方法





沒有留言:

張貼留言