4

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

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

我想在代码更改时重新启动每个 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 启动的 celery 守护进程不关闭的任何建议?非常感谢!

4

1 回答 1

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
于 2011-05-20T06:11:44.717 回答