Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to configure Monit on my local machine to get a taste at how it works, but I have some issues.

What I am trying to do is to get any evidence that Monit is up and running correctly and is actually monitoring something. So my /etc/monit/monitrc looks like

set daemon  60
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
    basedir /var/lib/monit/events
    slots 100
set httpd port 2812 and
    allow username:password

check process apache2 with pidfile /usr/local/apache/logs/apache2.pid
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if failed port 6543 protocol http then exec "/usr/bin/touch /tmp/monit"

If I understand correctly, since apache does not listen on port 6543 (it is just a random number) I should get an error, and as a consequence the file /tmp/monit should be created. So I start monit by

sudo service monit start
sudo monit monitor apache2

Unfortunately no such file is created. Instead the web console shows an error for apache - execution failed. The log says 'apache2' failed to start.

What am I doing wrong?

EDIT As suggested in the comments, I ran monit in verbose mode, by

monit -vv monitor apache2

(the exact command suggested in the comments failed). The output is

Runtime constants:
 Control file       = /etc/monit/monitrc
 Log file           = /var/log/monit.log
 Pid file           = /var/run/monit.pid
 Debug              = True
 Log                = True
 Use syslog         = False
 Is Daemon          = True
 Use process engine = True
 Poll time          = 60 seconds with start delay 0 seconds
 Expect buffer      = 256 bytes
 Event queue        = base directory /var/lib/monit/events with 100 slots
 Mail from          = (not defined)
 Mail subject       = (not defined)
 Mail message       = (not defined)
 Start monit httpd  = True
 httpd bind address = Any/All
 httpd portnumber   = 2812
 httpd signature    = True
 Use ssl encryption = False
 httpd auth. style  = Basic Authentication

The service list contains the following entries:

Process Name          = apache2
 Pid file             = /usr/local/apache/logs/apache2.pid
 Monitoring mode      = active
 Start program        = '/etc/init.d/apache2 start' timeout 30 second(s)
 Stop program         = '/etc/init.d/apache2 stop' timeout 30 second(s)
 Existence            = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Pid                  = if changed 1 times within 1 cycle(s) then alert
 Ppid                 = if changed 1 times within 1 cycle(s) then alert
 Port                 = if failed localhost:6543 [HTTP via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then exec '/usr/bin/touch /tmp/prova-monit' timeout 0 cycle(s) else if succeeded 1 times within 1 cycle(s) then alert

System Name           = system_andrea-Vostro-420-Series
 Monitoring mode      = active
share|improve this question
    
By the way, I am not sure whether the question belongs here or on superuser. Please, feel free to migrate if needed. –  Andrea Jun 4 '12 at 16:03
    
I know this is trivial but does running "/etc/init.d/apache2 start" start apache? Does that produce any errors? –  에이바 Jun 4 '12 at 16:03
    
Debug monit by starting it with: monit -c confhere -vv -I. What do you see? –  3molo Jun 4 '12 at 16:03
1  
Try using /var/run/httpd.pid as your pid file? –  에이바 Jun 4 '12 at 16:18
1  
(I actually kept checking that the PID file existed under /var/run and never realized that I was referring to a different file in the config...) –  Andrea Jun 4 '12 at 16:24
show 5 more comments

1 Answer 1

up vote 2 down vote accepted

PID files are normally located under /var/run.

In your /etc/monit/monitrc you're referencing a pidfile under /usr/local/apache/logs/apache2.pid.

Try changing this to match Apache's pidfile in /var/run.

It should be one of the following:

/var/run/httpd.pid 

or

/var/run/apache2.pid
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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