简体   繁体   English

在monit中滚动重启进程组

[英]Rolling restart of process group in monit

Does anyone have any suggestions of how I might go about achieving a rolling restart of a process group using monit? 有没有人有任何关于如何使用monit实现滚动重启进程组的建议?

Thanks in advance, fturtle 提前谢谢,fturtle

I'm not sure for which server you are talking about. 我不确定你在说什么服务器。 But I can provide you an example for thin which supports rolling restart itself. 但我可以为您提供一个支持滚动重启的瘦身示例。 (option onebyone: true ) (选项onebyone: true

So for monit you can use something like, 所以对于monit你可以使用类似的东西,

if ... then exec '/path/to/thin_restart.sh'

And thin_restart.sh would be something like, thin_restart.sh会是这样的,

source /path/to/scripts/rvm
rvm use your_gemset@some_ruby
thin -C thin.yml restart

And contents of thin.yml would look like, thin.yml的内容看起来像,

port: 1337
pid: tmp/pids/thin.pid
rackup: /path/to/config.ru
daemonize: true
servers: 2
onebyone: true

There are other ways to fine tune this restarts based on pid. 还有其他方法可以根据pid微调此重新启动。 You can monitor files with pids and restart only those thin process based on conditions. 您可以使用pids监视文件,并根据条件仅重新启动这些精简进程。

eg 例如

check process app-1337
  with pid /path/to/app.1337.pid
  start = 'thin -d -p 1337 start'
  stop  = 'thin -d -p 1337 -P /path/to/thin.1337.pid stop'
  if cpu usage > 50% then restart
check process app-1338
  with pid /path/to/app.1338.pid
  start = 'thin -d -p 1338 start'
  stop  = 'thin -d -p 1338 -P /path/to/thin.1338.pid stop'
  if cpu usage > 50% then restart

The other way would be of using groups which monit provides. 另一种方式是使用monit提供的组。

Extending above example. 扩展上面的例子。

check process app-1337
  with pid /path/to/app.1337.pid
  group thin
  group thin-odd
  start = 'thin -d -p 1337 start'
  stop  = 'thin -d -p 1337 -P /path/to/thin.1337.pid stop'
  if cpu usage > 50% then restart
check process app-1338
  with pid /path/to/app.1338.pid
  group thin
  group thin-even
  start = 'thin -d -p 1338 start'
  stop  = 'thin -d -p 1338 -P /path/to/thin.1338.pid stop'
  if cpu usage > 50% then restart
check process app-1337
  with pid /path/to/app.1339.pid
  group thin
  group thin-odd
  start = 'thin -d -p 1339 start'
  stop  = 'thin -d -p 1339 -P /path/to/thin.1339.pid stop'
  if cpu usage > 50% then restart
check process app-1340
  with pid /path/to/app.1340.pid
  group thin
  group thin-even
  start = 'thin -d -p 1340 start'
  stop  = 'thin -d -p 1340 -P /path/to/thin.1340.pid stop'
  if cpu usage > 50% then restart

So now you can do following to restart all: 所以现在你可以做以下重启所有:

monit -g thin restart

or to achieve sort of rolling restart, restart odd ones then even. 或实现滚动重启,然后重启奇数。 To restart only odd ones: 要重新启动奇数:

monit -g thin-odd restart

and to restart even: 并重新启动:

monit -g thin-even restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM