用上帝监视独角兽; “神日志独角兽”陷入困境

时间:2014-03-07 14:55:30

标签: ruby-on-rails ruby unicorn god

我在CentOS 6.5上运行上帝来监视与nginx一起使用的独角兽,以便在rails应用程序上部署ruby。我可以毫无问题地启动上帝和独角兽,但是当我运行命令时

god log unicorn

我收到“请稍候......”消息,但之后没有任何反应。我等了大约一个小时没有发生任何事情。有谁知道会导致什么?我尝试在谷歌搜索它,绝对没有。我的神配置文件直接来自http://www.synbioz.com/blog/monitoring_server_processes_with_god。我到了那个告诉你尝试上帝独角兽的部分。这是我基于该链接中的一个unicorn.god文件。它略有不同。

rails_root = File.dirname("/home/username/myApp")

God.watch do |w|
  pid_file = File.join(rails_root, "myApp/pids/unicorn.pid")

  w.name = "unicorn"
  w.interval = 60.seconds
  w.start = "unicorn -c #{rails_root}/myApp/config/unicorn.rb -D"
  w.stop = "kill -s QUIT $(cat #{pid_file})"
  w.restart = "kill -s HUP $(cat #{pid_file})"
  w.start_grace = 20.seconds
  w.restart_grace = 20.seconds
  w.pid_file = pid_file

  w.behavior(:clean_pid_file)

  # When to start?
  w.start_if do |start|
    start.condition(:process_running) do |c|
      # We want to check if deamon is running every ten seconds
      # and start it if itsn't running
      c.interval = 10.seconds
      c.running = false
    end
  end

  # When to restart a running deamon?
  w.restart_if do |restart|
    restart.condition(:memory_usage) do |c|
      # Pick five memory usage at different times
      # if three of them are above memory limit (100Mb)
      # then we restart the deamon
      c.above = 100.megabytes
      c.times = [3, 5]
    end

    restart.condition(:cpu_usage) do |c|
      # Restart deamon if cpu usage goes
      # above 90% at least five times
      c.above = 90.percent
      c.times = 5
    end
  end

  w.lifecycle do |on|
    # Handle edge cases where deamon
    # can't start for some reason
    on.condition(:flapping) do |c|
      c.to_state = [:start, :restart] # If God tries to start or restart
      c.times = 5                     # five times
      c.within = 5.minute             # within five minutes
      c.transition = :unmonitored     # we want to stop monitoring
      c.retry_in = 10.minutes         # for 10 minutes and monitor again
      c.retry_times = 5               # we'll loop over this five times
      c.retry_within = 2.hours        # and give up if flapping occured five times in two hours
    end
  end
end

0 个答案:

没有答案
相关问题