2011-05-11 136 views
4

我有一個運行5個不同django站點的Ubuntu服務器。這些用於測試,因此每個開發人員都有自己的站點和數據庫以及一個用於集成代碼的站點,只有在功能準備就緒時纔會更新。只要將更改推送到存儲庫,Jenkins就會用來從Github更新每個站點。使用Jenkins自動啓動多個芹菜守護進程

我們最近將Django-Celery添加到了我們的依賴項中,以便我們可以異步地對上傳的文件進行一些處理。每個站點現在需要自己的芹菜隊列,該隊列使用該特定站點的正確設置(數據庫,上傳目錄等)。

我想在每次代碼更改時重啓每個芹菜服務器,以便它可以自動獲取最新的更改。我們在我們的git倉庫中有一個更新腳本,Jenkins在更新站點時運行。當我嘗試在這個腳本中啓動一個芹菜守護進程時,芹菜啓動,但在腳本結尾處再次關閉。

這裏是我的更新腳本的副本:這個腳本的執行過程中

#!/bin/bash 

# Delete all *.pyc files 
find $WORKSPACE -name '*.pyc' | xargs rm 

# Update the database 
[…] 

# Run automated tests 
python code/manage.py test <project> --noinput 
TEST_STATUS=$? 

# Refresh this repo's public website 
touch $WORKSPACE/apache/wsgi.py 

# Restart our celery daemon for this installation 
/sbin/start-stop-daemon --stop -p $WORKSPACE/../celery.pid 
echo 'Starting Celery Server' 

# When run on the command line, this line starts a daemon just fine 
/sbin/start-stop-daemon --start --background --quiet --oknodo -p $WORKSPACE/../celery.pid -m --exec $WORKSPACE/code/manage.py -- celeryd --logfile=$WORKSPACE/../celery.log 

echo 'Celery Server Status: '$? 

exit $TEST_STATUS 

這裏的芹菜日誌的副本:

[2011-05-10 20:45:41,286: WARNING/MainProcess] -------------- [email protected] v2.2.6 
---- **** ----- 
--- * *** * -- [Configuration] 
-- * - **** --- . broker:  djkombu.transport.DatabaseTransport://[email protected]:5672/ 
- ** ---------- . loader:  djcelery.loaders.DjangoLoader 
- ** ---------- . logfile:  /var/lib/jenkins/jobs/mpdaugherty-farmforce/workspace/../[email protected] 
- ** ---------- . concurrency: 1 
- ** ---------- . events:  OFF 
- *** --- * --- . beat:  OFF 
-- ******* ---- 
--- ***** ----- [Queues] 
-------------- . celery:  exchange:celery (direct) binding:celery 
[2011-05-10 20:45:41,333: WARNING/MainProcess] [email protected] has started. 
[2011-05-10 20:46:28,481: WARNING/MainProcess] celeryd: Warm shutdown (MainProcess) 

對我如何能得到芹菜守護進程任何意見詹金斯開始不關閉?非常感謝!

回答

7

我的一位同事終於完成了這項工作。我們不用直接啓動Celery守護進程,而是使用at來立即安排它,並從當前shell斷開連接。

相反的:

# Restart our celery daemon for this installation 
/sbin/start-stop-daemon --stop -p $WORKSPACE/../celery.pid 
echo 'Starting Celery Server' 

# When run on the command line, this line starts a daemon just fine 
/sbin/start-stop-daemon --start --background --quiet --oknodo -p $WORKSPACE/../celery.pid -m --exec $WORKSPACE/code/manage.py -- celeryd --logfile=$WORKSPACE/../celery.log 

更改爲:

# Restart our celery daemon for this installation 
echo "/sbin/start-stop-daemon --stop -p $WORKSPACE/../celery.pid 
echo 'Starting Celery Server'" | at now 

# When run on the command line, this line starts a daemon just fine 
echo "/sbin/start-stop-daemon --start --background --quiet --oknodo -p $WORKSPACE/../celery.pid -m --exec $WORKSPACE/code/manage.py -- celeryd --logfile=$WORKSPACE/../celery.log" | at now 
+0

這真是救了我從一個頭痛的問題。但任何人都可以解釋爲什麼這個「現在」的作品,但原來的版本不? – timop