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
0

2 Answers 2

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.

1
  • 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, 2012 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.

6
  • It's CentOS 5.4. PID file is correct.
    – dunxd
    Feb 23, 2012 at 21:56
  • Using your config on a CentOS 5 server, I get Process 'apache' status Does not exist monitoring status monitored
    – ewwhite
    Feb 23, 2012 at 22:03
  • Where are you seeing that output?
    – dunxd
    Feb 23, 2012 at 22:10
  • You should quote your pidfile path "/var/run/httpd/httpd.pid". Also see the note I placed in the initial answer about a possible need for a VirtualHosts directive.
    – ewwhite
    Feb 23, 2012 at 22:13
  • Makes no difference quoted or not.
    – dunxd
    Feb 23, 2012 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .