简体   繁体   English

监视/失败时重新启动服务

[英]Monit / restart service when failed

I have a service, which is a server which listening to port: 7000. 我有一个服务,这是一个侦听端口7000的服务器。

I want to verify that the service is always up, and when it fails I want to start it again. 我想验证该服务始终处于启动状态,当它失败时,我想再次启动它。

I wrote the next script in /etc/monit.d/myserver 我在/etc/monit.d/myserver中写了下一个脚本

check process myserver with pidfile /var/run/myserver.pid
    start program = "/etc/init.d/myserver start" with timeout 5 seconds
    stop program  = "/etc/init.d/myserver stop" with timeout 5 seconds
    if failed host 127.0.0.1 port 7000
        protocol HTTP request /testcheck then restart
    if 5 restarts within 5 cycles then timeout

But I notice that even when the process is running, it restart the service, and give the next information on the log: 但是我注意到,即使进程正在运行,它也会重新启动服务,并在日志中提供以下信息:

EST Dec 18 03:05:13] error    : HTTP: error receiving data -- Resource temporarily unavailable
[EST Dec 18 03:05:13] error    : 'myserver ' failed protocol test [HTTP] at INET[127.0.0.1:7000] via TCP
[EST Dec 18 03:05:13] info     : 'myserver ' trying to restart
[EST Dec 18 03:05:13] info     : 'myserver ' stop: /etc/init.d/myserver 
[EST Dec 18 03:05:14] info     : 'myserver ' start: /etc/init.d/myserver 

How can I check it correctly so just when the service is down, it will restart it? 如何正确检查它,以便仅在服务关闭时才能重新启动它?

我遇到了同样的问题,最后我发现我没有正确运行monit守护进程,请看一下这篇文章: 如果进程停止,请在Monit中重新运行进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM