[Top][All Lists]

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

Re: Anyway to detect application startup failure within monit?

From: Lukasz Piwowarek
Subject: Re: Anyway to detect application startup failure within monit?
Date: Tue, 17 Jan 2012 17:58:11 -0700


I use Monit to check Nginx, Node.js and RedisDB and Monit already reports if the service failed to start. I do not know much about Monit - in all cases however my init scripts for these programs are more "standard" if you will - I do not use Monit to start the service - I assume Monit reads the exit code from the init script and reports failure or success based on that.

For example this is how I start RedisDB:

# Variable Definitions


[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis

start() {
        if [ -x $REDIS ] ; then
                if [ -f $CONFIG ] ; then
                        echo -n $"Starting RedisDB: "
                        daemon $REDIS $CONFIG
                        [ $RETVAL -eq 0 ] && touch $LOCKFILE
                        return $RETVAL
                        echo -n $"Cannot find RedisDB configuration at $CONFIG."
                else -n $"Cannot find RedisDB executable at $REDIS."

Hope this helps.



On Tue, Jan 17, 2012 at 5:28 PM, Kun Xi <address@hidden> wrote:

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?


To unsubscribe:

reply via email to

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