3

The solution was to replace this line:

check process apache with pidfile /var/run/httpd.pid

With this line:

check process httpd with pidfile /var/run/httpd/httpd.pid

And I also removed the 'group apache'.

Original post:

After installing Monit on CentOS, and setting an alert for the Apache (httpd) service, the service no longer creates the /var/run/httpd.pid file.

The httpd service IS running properly.

On top of it, as if that's not enough, Monit reports the status of the service as: Execution failed

Naturally, the only way to restart such a service is by killing it, since the 'restart' script doesn't see any running process.

These are the contents of the /etc/monit.d/monitrc file:

set daemon  10
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: me@server.com }
set alert bugs@server.com
set httpd port 2812 and
#     SSL ENABLE
#     PEMFILE  /var/certs/monit.pem
allow user:password

check process apache with pidfile /var/run/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program  = "/etc/init.d/httpd stop"
if cpu is greater than 180% for 1 cycles then alert
if totalmem > 1200 MB for 2 cycles then restart
if children > 250 then restart

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh for 5 cycles then restart
if 5 restarts within 25 cycles then timeout

Output of "service httpd restart":

Stopping httpd:                                            [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
                                                       [FAILED]

Any help will be greatly appreciated.

bizna
  • 702
  • 8
  • 23
  • Don't you mean "monit restart httpd"? What about "monit stop httpd" and "monit start httpd"? Does monit stop/start/restart sshd OK? – David Resnick Apr 28 '11 at 14:47
  • Thanks abunetta. When doing a restart, stop, start with Monit to httpd, there is no message. But the service isn't being stopped as well. I can't try to stop sshd, since it will leave me out of my machine :-) – bizna Apr 29 '11 at 13:38
  • Try using the advice found here: http://stackoverflow.com/questions/3356476/debugging-monit/4439403#4439403 to better see what's happening when monit calls stop. I assume that stop command in monitrc works when you call it from the command line. About "monit restart sshd"; I'd still recommend trying it as a sanity check. You'll manage to get back into the machine somehow, if it doesn't work :-) – David Resnick Apr 30 '11 at 19:15
  • The problem was, that for some reason the Monit restart of the service would eventually delete the process ID file, without creating a new one. The solution was to echo the correct ID into the ID file, before restarting the service. – bizna Jul 12 '11 at 04:24
  • Could you please provide the command you used to achieve this. I'm having the same problem. – greatwitenorth May 04 '12 at 19:52
  • The solution should not be the 'echo' that I previosly wrote about, but to correct the monitrc configuration file. The right thing to do is to change the 'set process apache' to 'set process httpd', and also have the proper path to the pid. My path was not correct. – bizna Aug 03 '12 at 08:10

3 Answers3

5

Try to replace stop program with /usr/sbin/httpd -k stop. It work for me.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
nophone
  • 51
  • 1
  • 2
0

I think that monit is doing a restart as 'stop; start' and is not waiting for 'stop' to finish before starting a new process, and thus is deleting the pid file at an inappropriate time. At least, that's my conclusion after tinkering with all this.

I found a reference to someone who fixed this issue by making monit sleep after the 'stop' statement.

Personally, I found that replacing 'restart' with 'start' when the http server is down worked just fine.

Mark
  • 1
0

I had the same problem but /usr/sbin/httpd -k stop didn't seem to help since this still tries to look up the process id from the pid file.

I opted for stop program = "/usr/bin/killall httpd". I don't think this is very elegant (probably kills open requests) but it was the only way I could find to restart apache and have the pid file recreated by monit.

Nic Cottrell
  • 9,401
  • 7
  • 53
  • 76