我创建了必须在崩溃时重新启动的monit应用程序golang site
$ cd /etc/monit/conf.d
$ vim checkSite
它启动程序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`"
它开始正常。
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
然后为了测试它如何在崩溃时重新启动,我手动杀死了它golang site。
这里我有两个问题:
站点重新启动相当慢:虽然在我设置的配置中需要 1 分钟 with timeout 5 seconds
即使在站点实际上重新启动后,sitein 的状态也会monit变为Does not exist。我猜这是因为在杀死并重新启动站点后pid会随机更改,但是我不知道如何克服这个问题。
重启后状态:
Process 'site'
status Does not exist
monitoring status Monitored
data collected Thu, 05 Mar 2015 08:04:44
如何减少重启时间以及如何修复站点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
12345678_0001
相关分类