如何监控Unicorn的非零停机时间?

时间:2013-09-26 17:13:23

标签: ruby-on-rails ruby nginx ruby-on-rails-4 unicorn

我发现了很多关于监控Unicorn的相互矛盾的信息,人们说其他配置脚本是错误的,并发布了自己的。似乎没有Just Works™

的主要配置

我假设preload_app并且零停机时间部署是罪魁祸首。我很乐意拥有它,但是现在我对监控运行更有兴趣了。所以目前关闭了所有这些设置。

现在我正在使用capistrano-unicorn这是一个非常棒的宝石。

它给了我所有需要重新加载独角兽的capistrano部署钩子。该应用已经成功部署了它。

我现在要做的主要事情是......

a)确保unicorn在服务器故障/重启时自动启动

b)监视独角兽重新启动死亡/挂起/无论什么的工人。

如果我正在使用这个宝石,那么完成我的目标可能是最好的方法(记住我不一定需要零停机时间)?

由于

1 个答案:

答案 0 :(得分:0)

引擎码使用Monit,这是一个非常实用的功能,可以完全满足您的需求!

以下是独角兽的配置:

check process unicorn
  with pidfile /path/to/unicorn.pid
  start program = "command to start unicorn"
    as uid yourUID and gid yourGID
    stop program = "command to stop unicorn"
    as uid yourUID and gid yourGID
  if mem > 255.0 MB for 2 cycles then restart
  if cpu > 100% for 2 cycles then restart

  check process unicorn_worker0
  with pidfile /path/to/unicorn_worker_0.pid
  if mem > 255.0 MB for 2 cycles then exec "/bin/bash -c '/bin/kill -6 `cat /path/to/unicorn_worker_0.pid` && sleep 1'"
...