1

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

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
4

0 回答 0