开发者

Monit on CentOS causes httpd.pid not to be created

开发者 https://www.devze.com 2023-03-01 13:03 出处:网络
The solution was to replace this line: check proces开发者_开发知识库s apache with pidfile /var/run/httpd.pid

The solution was to replace this line:

check proces开发者_开发知识库s 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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消