Question

I'm trying to monitor my server and just want to restart it when its down. Following is my monit control

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

But even if the server is running monit gives error like:

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

How do I fix this? Am I making some mistakes?

Also when I try to use 'send' and 'expect' it gives error like

Erro: syntax error 'send'.
Was it helpful?

Solution

You might need to specify UID and GID as monit runs as 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

To debug, you could try to output to a file and check this file to have more details.

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

For the send and expect, you might not need it for http query as the http protocol is supported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top