使用Jenkins自动启动多个celery守护进程

时间:2011-05-11 18:05:04

标签: django deployment jenkins celery start-stop-daemon

我有一个Ubuntu服务器,其上运行着5个不同的django站点。这些用于测试,因此每个开发人员都有自己的站点和数据库以及一个集成代码站点,只有在功能准备就绪时才会更新。每当更改被推送到存储库时,Jenkins都会使用Github更新每个站点。

我们最近将Django-Celery添加到我们的依赖项中,以便我们可以异步地对上传的文件进行一些处理。现在每个站点都需要自己的芹菜队列,该队列使用该特定站点的正确设置(数据库,上传目录等)。

我想在代码更改时重启每个芹菜服务器,以便自动获取最新的更改。我们的git存储库中有一个更新脚本,Jenkins会在更新站点时运行。当我尝试在此脚本中启动celery守护程序时,celery启动,但在脚本结束时再次关闭。

以下是我的更新脚本的副本:

#!/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] -------------- celery@ip-10-227-139-6 v2.2.6
---- **** -----
--- * ***  * -- [Configuration]
-- * - **** ---   . broker:      djkombu.transport.DatabaseTransport://guest@localhost:5672/
- ** ----------   . loader:      djcelery.loaders.DjangoLoader
- ** ----------   . logfile:     /var/lib/jenkins/jobs/mpdaugherty-farmforce/workspace/../celery.log@WARNING
- ** ----------   . concurrency: 1
- ** ----------   . events:      OFF
- *** --- * ---   . beat:        OFF
-- ******* ----
--- ***** ----- [Queues]
 --------------   . celery:      exchange:celery (direct) binding:celery
[2011-05-10 20:45:41,333: WARNING/MainProcess] celery@ip-10-227-139-6 has started.
[2011-05-10 20:46:28,481: WARNING/MainProcess] celeryd: Warm shutdown (MainProcess)

关于我如何获得芹菜守护进程的建议是由Jenkins开始不关闭的?非常感谢!

1 个答案:

答案 0 :(得分: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