Django 使用Jenkins自动启动多个芹菜守护进程

Django 使用Jenkins自动启动多个芹菜守护进程,django,deployment,jenkins,celery,start-stop-daemon,Django,Deployment,Jenkins,Celery,Start Stop Daemon,我在Ubuntu服务器上安装了5个不同的django站点。这些用于测试,因此每个开发人员都有自己的站点和数据库,以及一个集成代码站点,只有在特性就绪时才会更新。Jenkins用于在将更改推送到存储库时从Github更新每个站点 我们最近在依赖项中添加了Django芹菜,这样我们就可以异步处理上传的文件。每个站点现在都需要自己的芹菜队列,该队列为特定站点使用正确的设置(数据库、上载目录等) 我想在代码更改时重新启动每个芹菜服务器,这样它就可以自动获得最新的更改。我们在git存储库中有一个更新脚本,

我在Ubuntu服务器上安装了5个不同的django站点。这些用于测试,因此每个开发人员都有自己的站点和数据库,以及一个集成代码站点,只有在特性就绪时才会更新。Jenkins用于在将更改推送到存储库时从Github更新每个站点

我们最近在依赖项中添加了Django芹菜,这样我们就可以异步处理上传的文件。每个站点现在都需要自己的芹菜队列,该队列为特定站点使用正确的设置(数据库、上载目录等)

我想在代码更改时重新启动每个芹菜服务器,这样它就可以自动获得最新的更改。我们在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

关于如何让Jenkins启动的芹菜守护进程不关闭,有什么建议吗?非常感谢

我的一个同事终于成功了。我们没有直接启动芹菜守护进程,而是使用
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

这真的使我免于头痛。但是,有人能解释为什么“现在”有效,而原始版本无效吗?
# 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