11

I've just installed and configured monit according to the monit documentation. All services apart from Apache are listed as Running, but Apache says Not Monitored.

The relevant lines in monit's config are:

check process apache with pidfile /var/run/httpd.pid
        group www
        start program = "/etc/init.d/httpd start"
        stop program = "/etc/init.d/httpd stop"
        if failed host localhost port 80
        protocol http then restart
        if 5 restarts within 5 cycles then timeout

I can access http://localhost/server-status and http://localhost fine from the server. Monit lists Monitoring mode for Apache as active.

Server is running CentOS 5.4.

PID file is correct for parent httpd server:

[server ~]$ cat /var/run/httpd.pid
2905
[server ~]$ ps auxc | grep httpd
root      2905  0.0  0.9  26952  4808 ?        Ss   11:36   0:00 httpd
dunxd
  • 9,482
  • 21
  • 80
  • 117

2 Answers2

14

Make sure the contents of the pid file match up with the Apache master process's pid (i.e., the httpd process that runs as root). It's possible the pid file is stale.

If it's stale, get the pid of the Apache master process, and do something like echo 1234 > /var/run/httpd.pid, where 1234 is the pid in question.

After that, run monit monitor apache to restart monitoring of that service.

the
  • 468
  • 8
  • 23
cjc
  • 24,533
  • 2
  • 49
  • 69
  • 2
    The PID file was correct, but running `monit monitor apache` got it started, and now it seems to be working fine after restarting the service. I should also have tried clicking the Enable Monitor button on the web interface. – dunxd Feb 24 '12 at 22:46
1

You don't provide the OS version/distribution, but on CentOS 6, the PID file you should be monitoring is located at: /var/run/httpd/httpd.pid

So change to:

check process apache with pidfile /var/run/httpd/httpd.pid

Incidentally, CentOS 5 has the Apache PID file in: /var/run/httpd.pid

Edit: Also quote the PID path.

There's a note on the Monit mailing list about the protocol test you're using:

http://lists.gnu.org/archive/html/monit-general/2004-12/msg00057.html

You may need to pass a hostname or site name if you're using name-based virtual hosts.

ewwhite
  • 194,921
  • 91
  • 434
  • 799