monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Anyway to detect application startup failure within monit?


From: Kun Xi
Subject: Anyway to detect application startup failure within monit?
Date: Tue, 17 Jan 2012 16:28:02 -0800

Hello,

tl;dr: go to the end for the question, please.

We are trying to use monit to start/monitor some services, and the
basic workflow is:

Start monit very early as a system-level service using init script.
In service foo init script, create a foo.conf in /etc/monit/conf.d
Reload monit
monit start foo

==== monitrc  snippet ====
set daemon 5
set logfile syslog facility log_daemon
set pidfile /tmp/monit-wfe1.pid
set idfile /var/run/monit/monit.id
set statefile /var/run/monit/monit.state
set httpd port 2812 and use the address 127.0.0.1
    allow localhost

include /etc/monit/conf.d/*
==== monitrc snippet ====

The service foo's monit config
==== conf.d/foo.conf ===

check process foo with pidfile /tmp/foo.pid
   start "/opt/bin/foo --pidfile /tmp/foo-wfe1.pid --instance-id foo-wfe1  -d"
   stop "/sbin/start-stop-daemon --stop --quiet -R 120 --oknodo
--pidfile /tmp/foo-wfe1.pid"
   if failed host 192.168.0.16 port 8086 protocol http
       and request '/ping'
       with timeout 5 seconds for 4 cycles
   then restart
==== conf.d/foo.conf ====

Here is the init script snippet to start service foo:
==== init.d/foo ====
function start() {
   monit_config # create the conf.d/foo.conf using the magic
environment variable
    /usr/sbin/monit -c $MONIT_RC reload
    while :
    do
        sleep 1
        /usr/sbin/monit -c $MONIT_RC start foo
        STATUS=`/usr/sbin/monit -c $MONIT_RC summary | sed -n
"s/Process 'foo' *\([a-z]*\)/\1/p"`
        if [ "$STATUS" = 'running' ]; then
            break
        fi
    done
    RETVAL=0
}
==== init.d/foo ====

The service foo may crash in startup due to the corrupted configure
file, incompatible environment . This approach will keep retrying it,
and to make things worse, monit does not handle the process crash very
well, the stderr is filled with:

monit: cannot read status from the monit daemon

QUESTION:
Any way to detect the process died in the startup in monit, and what
is appropriate approach for monitor to bail out in such a scenario,
for example, unmonitor and return the error status from foo?

Thanks,
Kun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]