Monit在服务器未运行时记录运行进程

时间:2013-09-20 11:33:29

标签: monitoring monitor monit

我正在尝试监控我的服务器,只是想在它关闭时重新启动它。以下是我的监控

check process myserver with pidfile "/home/path/to/myserver.pid"
start program = "/etc/init.d/myserver start"
stop program = "/etc/init.d/myserver stop"
if failed host 127.0.0.1 port 8080 protocol http
then restart

但即使服务器运行monit也会出现如下错误:

'myserver' process not running
trying to restart 'myserver'
failed to restart myserver.

我该如何解决这个问题?我犯了一些错误吗?

当我尝试使用'send'和'expect'时,它会出现错误,如

Erro: syntax error 'send'.

1 个答案:

答案 0 :(得分:1)

您可能需要指定UID和GID,因为monit以root身份运行。

check process myserver 
  with pidfile "/home/path/to/myserver.pid"
  start program = "/etc/init.d/myserver start"
    as uid myserver_uid and gid myserver_gid
  stop program = "/etc/init.d/myserver stop"
    as uid myserver_uid and gid myserver_gid
if failed host 127.0.0.1 port 8080 protocol http
then restart

要进行调试,您可以尝试输出到文件并检查此文件以获取更多详细信息。

check process myserver 
  with pidfile "/home/path/to/myserver.pid"
  start program = "/etc/init.d/myserver start >> /tmp/myserver.log 2>&1"
    as uid myserver_uid and gid myserver_gid
  stop program = "/etc/init.d/myserver stop  >> /tmp/myserver.log 2>&1"
    as uid myserver_uid and gid myserver_gid
if failed host 127.0.0.1 port 8080 protocol http
then restart

对于send和expect,由于支持http协议,因此http查询可能不需要它。