[Top][All Lists]

[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


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/
set idfile /var/run/monit/
set statefile /var/run/monit/monit.state
set httpd port 2812 and use the address
    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/
   start "/opt/bin/foo --pidfile /tmp/ --instance-id foo-wfe1  -d"
   stop "/sbin/start-stop-daemon --stop --quiet -R 120 --oknodo
--pidfile /tmp/"
   if failed host 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 :
        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
==== 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

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?


reply via email to

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