OK, then you can monitor some dummy tag file which will be touched when apache start method is called, something like this (see the apache2's "start program ..." modification and new file path):
--8<-- check process apache2_webserver with pidfile /var/run/apache2.pid depends on mysql_DBserver, heartbeat start program = "/bin/bash -c '/etc/init.d/apache2 start; touch /tmp/.apache_restarted'" stop program = "/etc/init.d/apache2 stop" if failed host 127.0.0.1 port 80 protocol http for 4 times within 4 cycles then exec "/usr/lib/heartbeat/hb_standby" group wwwdata mode manual
check file apache_restart_tag with path "/tmp/.apache" if changed timestamp for 4 cycles then exec "/usr/lib/heartbeat/hb_standby" --8<--
There is also statement in Monit which can be extended in the future to allow much simpler configuration of the same (currently only timeout i.e. unmonitor action is supported however):
if 4 restarts within 4 cycles then timeout
... the "timeout" can be replaced for any action, which will be implemented in the future
Martin
On Nov 5, 2008, at 9:03 PM, Vianney Lejeune wrote: Your configuration will execute the "/usr/lib/heartbeat/hb_standby" only in the case, that the protocol test of http://127.0.0.1:80 failed 4 times. This test is evaluated however only in the case that the process is running - if apache is not running, monit skips the other tests since it knows that they will fail (the running process is prerequisite) and performs the restart action directly.
If you want to bind the hb_standby action to the case when the apache restarted 4 times in 4 cycles as well, you can use workaround such as watching the pidfile in addition to apache process like this:
--8<--
check file with path "'/var/run/apache2.pid"
if changed timestamp for 4 cycles then exec "/usr/lib/heartbeat/hb_standby"
--8<--
Thank for your reply, but please have a look about that: monit[13848]: 'apache2.pid' file existence check passed monit[13848]: 'apache2.pid' is regular file monit[13848]: 'apache2.pid' timestamp was not changed for /var/run/apache2.pid Then, I corrupt the apache2's configuration file and kill apache2: monit: pidfile '/var/run/apache2.pid' does not exist monit[13848]: Monitoring enabled -- service apache2_webserver monit: pidfile '/var/run/apache2.pid' does not exist monit[13848]: monit: pidfile '/var/run/apache2.pid' does not exist monit[13848]: monit: pidfile '/var/run/apache2.pid' does not exist monit[13848]: monit: pidfile '/var/run/apache2.pid' does not exist monit[13848]: monit: pidfile '/var/run/apache2.pid' does not exist In this case, there is no takeover. Regards, Vianney
Please run monit in verbose mode (-v option) and check output (logfiles).
Martin
Well, it seems that if apache is crashed, there is not pidfile, so monit doesn't perform any test according to the log files. If apache is running, monit performs it.
What can I do?
Log:
======
monit[20683]: 'apache2_webserver' succeeded testing protocol [HTTP] at INET[localhost:80] via TCP
monit[20683]: monit: pidfile '/var/run/apache2.pid' does not exist
monit[22347]: 'apache2_webserver' process is not running
monit[22347]: 'apache2_webserver' trying to restart
monit[22347]: Monitoring disabled -- service apache2_webserver
monit[22347]: monit: pidfile '/var/run/apache2.pid' does not exist
monit[22347]: 'apache2_webserver' start: /etc/init.d/apache2
monit[22347]: monit: pidfile '/var/run/apache2.pid' does not exist
monit[22347]: Monitoring enabled -- service apache2_webserver
monit[22347]: monit: pidfile '/var/run/apache2.pid' does not exist
=====
Hello,
I really don't understand why it doesn't work. I tried many tutorials, read and reread the manual but I'm always unable to do something, this is a sample of my monitrc file:
=======
check process apache2_webserver with pidfile /var/run/apache2.pid
depends on mysql_DBserver, heartbeat
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80 protocol http for 4 times within 4 cycles then exec "/usr/lib/heartbeat/hb_standby"
group wwwdata
mode manual
=====
I know that hb_standby works, but I'm unable to trigger anything with this configuration, I replaced " exec "/usr/lib/heartbeat/hb_standby" " by unmonitor, timeout and so. Nothing is triggered. I'm just looking for a working configuration using the hb_standby based on a connection test, I wonder if something isn't wrong with monit on my system.
Regards,
Vianney
-- To unsubscribe: http://lists.nongnu.org/mailman/listinfo/monit-general
|