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
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
, where1234
is the pid in question.After that, run
monit monitor apache
to restart monitoring of that service.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:
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.