mmonit golang重启慢和状态不存在

Max*_*mov 7 go monit

我创建了必须在崩溃时重启的monit应用程序golang site

$ cd /etc/monit/conf.d 
$ vim checkSite 
Run Code Online (Sandbox Code Playgroud)

它启动程序nohup并将其保存pid到文件:

check process site with pidfile /root/go/path/to/goSite/run.pid
    start program = "/bin/bash -c 'cd /root/go/path/to/goSitePath; nohup ./goSite > /dev/null 2>&1 & echo $! > run.pid'" with timeout 5 seconds
    stop program = "/bin/kill -9 `cat /root/go/path/to/goSitePath/run.pid`"
Run Code Online (Sandbox Code Playgroud)

它开始了.

Process 'site'
  status                            Running
  monitoring status                 Monitored
  pid                               29723
  parent pid                        1
  uptime                            2m 
  children                          0
  memory kilobytes                  8592
  memory kilobytes total            8592
  memory percent                    0.4%
  memory percent total              0.4%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Thu, 05 Mar 2015 07:20:32
Run Code Online (Sandbox Code Playgroud)

然后测试它将如何重新启动崩溃我手动杀死golang site.

我有两个问题:

  1. 站点重新启动相当慢:虽然在我设置的配置中需要1分钟 with timeout 5 seconds
  2. 事实上重新启动之后,sitein的状态monit变得Does not exist均匀.我猜这是因为杀死并重新启动网站后pid随机变化,但如何克服这个我不知道.

重启后的状态:

Process 'site'
      status                            Does not exist
      monitoring status                 Monitored
      data collected                    Thu, 05 Mar 2015 08:04:44
Run Code Online (Sandbox Code Playgroud)

如何减少重启的时间以及如何修复网站monit status

monit 日志:

[Mar  5 08:04:44] error    : 'site' process is not running
[Mar  5 08:04:44] info     : 'site' trying to restart
[Mar  5 08:04:44] info     : 'site' start: /bin/bash
[Mar  5 08:06:44] info     : 'site' process is running with pid 31479
Run Code Online (Sandbox Code Playgroud)

更新

我的golang网站很简单:

package main

import (
    "fmt"
    "github.com/go-martini/martini"
)

func main() {
    m := martini.Classic()

    m.Get("/", func() {
        fmt.Println("main page")
    })

    m.Run()
}
Run Code Online (Sandbox Code Playgroud)

更新2

我试图通过删除pid文件本身来提高monit重新加载我的golang网站的速度.说我做了kill 29723 && rm run.pid并打开计时器,以计算网站再次访问的时间.花了85秒.所以删除pid文件没有帮助monit提高重新加载网站的速度.

Jai*_*ano 5

monit没有任何订阅机制可以直接发现进程是否已终止。

如记录所示,在守护程序模式下,monit通过定期轮询所有已配置规则的状态来工作,其轮询周期是在守护程序启动时配置的,并且在某些Linux发行版中默认为2分钟,这意味着在这种情况下,monit可能需要2分钟内采取任何措施。

在monitrc中检查此配置,该配置已使用set daemon伪指令配置,例如,如果要每5秒检查一次状态,则应设置:

set daemon 5
Run Code Online (Sandbox Code Playgroud)

在每个周期中,它都会更新其状态,并根据需要执行操作。因此,如果它检测到该进程不存在,它将报告Does not exist直到下一个轮询周期,即使它已经决定要重新启动它。

timeoutstart daemon指令没有任何与本次调查周期,这是时间的monit将给予启动该服务。如果服务在这段时间内没有启动,monit将报告它。

如果monit不能满足您的要求,您也可以尝试使用administratord,它始终知道已执行程序的状态。