monit を使って、httpd (Apache HTTP Server) のプロセスが落ちたときに自動的に再起動するようにしている。まれに httpd が落ちるときがあって、monit が httpd を再起動しようとしたとき次のようなログがでていてうまく再起動できない現状に遭遇した。
[JST Feb 10 01:13:59] error : ‘httpd’ failed to start
[JST Feb 10 01:13:59] info : ‘httpd’ trying to restart
[JST Feb 10 01:13:59] info : ‘httpd’ start: /etc/init.d/httpd
[JST Feb 10 01:14:59] error : ‘httpd’ process is not running
[JST Feb 10 01:14:59] info : ‘httpd’ trying to restart
[JST Feb 10 01:14:59] info : ‘httpd’ start: /etc/init.d/httpd
[JST Feb 10 01:14:59] error : ‘httpd’ failed to start
よくよく調べてみると、一度 monit から httpd を起動したとき /var/lock/subsys/httpd ファイルや /var/run/httpd.pid ファイルが生成されない状態になって、monit が /var/run/httpd.pid がないので httpd が動いているのにも関わらず httpd を起動し続けていたことが原因。
/etc/init.d/httpd を修正しようと思ったが、monit の設定ファイルを次のように書き換えて対応したら、今のところは問題がない様子。
変更前
check process httpd with pidfile /var/run/httpd.pid
start program = “/sbin/service httpd start”
stop program = “/sbin/service httpd stop”
if failed host localhost port 80 protocol http
and request “/healthcheck/heartbeat”
for 3 cycles then restart
変更後
check process httpd with pidfile /var/run/httpd.pid
start program = “/sbin/service httpd restart”
stop program = “/sbin/service httpd stop”
if failed host localhost port 80 protocol http
and request “/healthcheck/heartbeat”
for 3 cycles then restart
さて、次は httpd が落ちる原因を調査して対策することにしよう。
Tags: httpd monit







