1

我想在我的部署过程中使用 Beanstalkd。这个想法类似于 IGN 使用的想法 ( https://github.com/ign/brood )。在任何给定时间,我都可能希望触发两个客户端下载最新代码并重新启动 Apache。是否可以让多个工作人员(每个客户端一个)处理同一个队列?作为一种解决方法,我可以为每个客户端创建一个队列。

4

1 回答 1

0

每个客户端的特定队列,用于该客户端的命令。让他们都听自己的队列,并根据需要向尽可能多的客户端发送简单的“RESTART”消息。

我有一个 bash 脚本来启动这项工作,并保持它运行以执行实际的重新启动。你的脚本只需要

  1. 删除“RESTART”消息(否则下次会收到相同的消息)
  2. exit(90);剧本

返回值由 Bash 脚本获取,并执行操作。

#!/bin/bash

# runBeanstalkd-worker.sh

# a shell script that keeps looping until an exit code is given
# if it does an exit(0), restart after a second - or if it's a declared error
# if we've restarted in a planned fashion, we don't bother with any pause
# and for one particular code, exit the script entirely.
# The numbers 97, 98, 99 must match what is returned from the PHP script

nice php -q -f ./cli-beanstalk-worker.php -- $@
ERR=$?

## Possibilities
# 90    - restart apache
# 97    - planned pause/restart
# 98    - planned restart
# 99    - planned stop, exit.
# 0     - unplanned restart (as returned by "exit;")
#        - Anything else is also unplanned paused/restart

# 90    - restart apache
if [ $ERR -eq 90 ]
then
   service apache restart
   sleep 5;
   exec $0 $@;
fi

if [ $ERR -eq 97 ]
then
   # a planned pause, then restart
   echo "97: PLANNED_PAUSE - wait 1";
   sleep 1;
   exec $0 $@;
fi

####   other actions, like planned-restart, or shutdown

# unplanned exit, pause, and restart
echo "unplanned restart: err:" $ERR;
echo "sleeping for 1 sec"
sleep 1

exec $0 $@
于 2013-09-28T08:35:09.807 回答