monit-general
[Top][All Lists]
Advanced

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

Re: Anyway to detect application startup failure within monit?


From: Martin Pala
Subject: Re: Anyway to detect application startup failure within monit?
Date: Wed, 18 Jan 2012 22:58:05 +0100

Hello,

if the monitored process is not running, monit tries to restart the service … 
the start script has associated timeout (by default 30 seconds) - if the 
process doesn't start on time, monit reports the start failure. The test 
doesn't depend on start script return value - monit checks the process table.

The message "cannot read status from the monit daemon" is logged if you use the 
monit CLI and it cannot contact the monit daemon via the monit http interface 
(for example when the httpd interface is disabled).

Regards,
Martin


On Jan 18, 2012, at 1:28 AM, Kun Xi wrote:

> 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
> 
> --
> To unsubscribe:
> https://lists.nongnu.org/mailman/listinfo/monit-general




reply via email to

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