重启 Upstart 实例进程 [英] Restarting Upstart instance processes

查看:28
本文介绍了重启 Upstart 实例进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个工作程序的多个实例,如本答案所述:自动启动多个新贵实例

I am running multiple instances of a worker as described in this answer: Starting multiple upstart instances automatically

问题:我可以一次重启所有实例吗?

要开始我的工作人员,我可以:

To start my workers I can do:

initctl start my-workers

initctl start my-workers

然后我可以这样做:

initctl status worker N=1 worker (1) start/running, process 551

initctl status worker N=1 worker (1) start/running, process 551

initctl status worker N=2 worker (2) start/running, process 552

initctl status worker N=2 worker (2) start/running, process 552

有没有办法做这样的事情:

Is there a way to do something like this:

initctl restart my-workers

initctl restart my-workers

我希望能够重新启动所有实例,而不必知道有多少实例正在运行.

I would like to be able to restart all instances without having to know how many are running.

这是我的 my-workers.conf

Here is my my-workers.conf

start on stopped cloud-init
stop on shutdown

env NUM_WORKERS=4

script
  for i in `seq 1 $NUM_WORKERS`
    do
      start worker N=$i
    done
end script

和worker.conf

And worker.conf

stop on shutdown

chdir /path/to/current

respawn

instance $N

script
  exec su -c "/home/worker/.rvm/bin/rvm-shell -c 'bundle exec rake work 2>&1 >> /var/log/worker-$N.log'" worker
end script

推荐答案

worker.conf 中你只需要改变这一行:

In worker.conf you just need to change this line:

stop on shutdown

致:

stop on stopping my-workers

并将 my-workers.conf 更改为使用 pre-start 而不是 script:

And change my-workers.conf to use pre-start instead of script:

pre-start script
  for i in `seq 1 $NUM_WORKERS`
  do
    start worker N=$i
  done
end script

现在 my-workers 将保持状态:由于工作发生在 pre-startmy-workers 主进程不会存在,所以不会退出.stop on stop my-workers 会导致 worker 在 my-workers 停止时停止.然后当然当它再次启动时,它会再次启动工人.

Now my-workers will keep state: since the work happens in pre-start, the my-workers main process won't exist and so won't exit. stop on stopping my-workers causes the workers to stop whenever my-workers is stopped. Then of course when it starts up again it will start the workers again.

(仅供参考,stop on shutdown 什么都不做,因为 shutdown 不是系统事件.man upstart-events 用于所有定义的事件) 所以你也应该将 my-workers 更改为 stop on runlevel [06]

(FYI, stop on shutdown does nothing, as shutdown is not a system event. man upstart-events for all the defined events) so you should also change my-workers to stop on runlevel [06]

这篇关于重启 Upstart 实例进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆