2

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?

6

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.

| improve this answer | |
  • I found: /var/run/apache2.pid – Bergen Jul 9 '13 at 20:27
  • @Bergen: there you go then - problem solved - ✔ – user9517 Jul 9 '13 at 20:28
  • In monitrc file i put: #apache2 check process apache2 with pidfile /var/run/apache2.pid group apache start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" if failed host 127.0.0.1 port 80 protocol http then restart if 5 restarts within 5 cycles then timeout – Bergen Jul 9 '13 at 20:28
1

On Centos, there is a good chance that you use "service" utility to manage deamons. Services are configured in directory: /etc/init.d/

In file /etc/init.d/httpd, you will find the pid file location. I see something like pidfile=${PIDFILE-/var/run/httpd/${prog}.pid}

So, it turns out that my pidfile is located at /var/run/httpd/httpd.pid

| improve this answer | |
0

Two things I would try:

  1. See if you can configure Apache to write out a PID file. Ref: http://httpd.apache.org/docs/2.2/mod/mpm_common.html#pidfile
  2. Modify apache2 start/stop script to create a PID file during the start/stop using the pgrep command. Ref: http://mmonit.com/wiki/Monit/ConfigurationExamples
| improve this answer | |
0

if you install Apache 2.4 or through chef cookbook(https://github.com/sous-chefs/apache2) then the location would be /var/run/apache2/apache2.pid

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.