0

我有这些rake偶尔会失败的任务。我想用它monit来监视它们并在必要时重新启动它们。

我已经阅读了 StackOverflow 上的其他 ruby​​/monit 线程。我的情况不同,因为这些程序需要我的 Rails 环境才能工作。这就是为什么我现在将它们作为rake任务。

这是我需要监控的任务之一:

task(process_updates: :environment) do
  `echo "#{Process.pid}" > #{Rails.root}/log/process_alerts.pid`
  `echo "#{Process.ppid}" > #{Rails.root}/log/process_alerts.ppid`
  SynchronizationService::process_alerts
end

我的问题是,我是否将其作为一项rake任务,因为SynchronizationService::process_alerts需要 Rails 环境才能工作?还是我应该调用其他一些包装器然后运行一些 *.rb 文件?

4

1 回答 1

1

Monit 可以检查正在运行的 pid,因为您在运行任务时创建了 pid,您可以创建一个 monit 配置,它应该看起来像这样:

check process alerts with pidfile RAILSROOT/log/process_alerts.pid
  start program = "cd PATH_TO_APP; rake YOURTASK" with timeout 120 seconds
  alert your@mail.com on { nonexist, timeout }

当然RAILSROOTPATH_TO_APPYOURTASK应该对应于你的路径/耙任务。

然后,Monit 将使用 pidfile 值检查系统中正在运行的进程,如果找不到正在运行的进程,它将使用start program命令启动该进程。

于 2013-10-31T20:42:54.133 回答