monit 中进程组的滚动重启

发布于 2024-09-27 03:04:46 字数 57 浏览 7 评论 0原文

有人对我如何使用 monit 实现进程组的滚动重启有任何建议吗?

提前致谢, 福特尔

Does anyone have any suggestions of how I might go about achieving a rolling restart of a process group using monit?

Thanks in advance,
fturtle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-10-04 03:04:46

我不确定你说的是哪个服务器。但我可以为您提供一个 Thin 的示例,它本身支持滚动重启。 (选项onebyone:true

因此,对于monit,您可以使用类似的内容,

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

thin_restart .sh 类似于,

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

thin.yml 的内容类似于,

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

还有其他方法可以根据 pid 微调此重新启动。您可以使用 pid 监视文件,并根据条件仅重新启动那些瘦进程。

例如,

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

另一种方法是使用 monit 提供的组。

扩展上面的例子。

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

因此,现在您可以执行以下操作来重新启动全部:

monit -g thin restart

或者要实现某种滚动重新启动,先重新启动奇数,然后重新启动偶数。
仅重新启动奇数:

monit -g thin-odd restart

并重新启动偶数:

monit -g thin-even restart

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)

So for monit you can use something like,

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

And thin_restart.sh would be something like,

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

And contents of thin.yml would look like,

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. You can monitor files with pids and restart only those thin process based on conditions.

e.g.

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文