Ubuntu – Can’t find httpd.pid to use for Monit apache2 monitoring

apache-2.2httpdmonitUbuntu

I'm new to Linux and I setup Ubuntu 12.04 on Digital Ocean.

I installed Monit and got it to monitor MySQL successfully with email alert.

I want to monitor Apache2 as well but cannot find any httpd.pid file needed to put in monitrc file.

I can start Apache2 with: /etc/init.d/apache2 start

I can stop Apache2 with: /etc/init.d/apache2 stop

I can restart Spache2 with: /etc/init.d/apache2 restart

What other way is there to monitor Apache2 in Monit without a httpd.pid file?

Best Answer

If you look in the init script it uses the value of $APACHE_PID_FILE which it reads from the file defined as $APACHE_ENVVARS which I think defaults to /etc/apache2/envvars

PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 

In the envvars file PIDFILE is defined as

APACHE_PID_FILE=/var/run/apache2$SUFFIX.pid

Unless you are running multiple instances of apache2 $SUFFIX will likely be "" so the value of $APACHE_PID_FILE will be

/var/run/apache2.pid

but you should be able to run

echo $(. /etc/apache2/envvars && echo $APACHE_PID_FILE) 

and get what your system thinks the value is.