Can't get Monit to work
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
Related videos on Youtube
Comments
-
Andrea over 1 year
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 likeset 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 bysudo 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
-
Andrea almost 12 yearsBy the way, I am not sure whether the question belongs here or on superuser. Please, feel free to migrate if needed.
-
에이바 almost 12 yearsI know this is trivial but does running "/etc/init.d/apache2 start" start apache? Does that produce any errors?
-
SiXoS almost 12 yearsDebug monit by starting it with: monit -c confhere -vv -I. What do you see?
-
Andrea almost 12 years@에이바 It does start Apache if it is not running. Otherwise one has to issue a restart, or a stop followed by a start. I thought Monit is smart enough to figure this out by looking at the pid file
-
Andrea almost 12 years@3molo I added the contents in the body of the qustion
-
Andrea almost 12 years@에이바 In any case, Apache is already running, so shouldn't Monit just start monitoring? I have also tried stopping apache before monitoring, but nothing changes
-
에이바 almost 12 yearsTry using /var/run/httpd.pid as your pid file?
-
Andrea almost 12 yearsI don't know why I was even using a pid file outside /var/run!! I had edited the line to use apache2.pid instead of httpd.pid, but I did not check that it was using the right directory! I assumed the default configuration was reasonable, but I guessi it assumes a manual install of apache. Anyway, that was the issue. If you post it an an answer, I'll be glad to accept it.
-
Andrea almost 12 years(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...)
-
에이바 almost 12 yearsIt happens. Glad I could help!
-