Kun,
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
REDIS=/usr/bin/redis-server
CONFIG=/etc/redis.conf
LOCKFILE=/var/lock/subsys/redis
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
start() {
if [ -x $REDIS ] ; then
if [ -f $CONFIG ] ; then
echo -n $"Starting RedisDB: "
daemon $REDIS $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
else
echo -n $"Cannot find RedisDB configuration at
$CONFIG."
fi
else -n $"Cannot find RedisDB executable at $REDIS."
fi
}
Hope this helps.
Cheers
Lukasz
On Tue, Jan 17, 2012 at 5:28 PM, Kun Xi <[email protected]> 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
>
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general