PDA

View Full Version : Monitoring daemons


luciano
09-15-2004, 10:21 PM
Hi,

I'm new to RimuHosting and to VPS in general. While I'm writing my script to monitor Tomcat and restart it automatically if it goes down, I'd like to know if someone has found any interesting application to monitor daemons and restart them.

retep
09-16-2004, 04:46 AM
Hi. I have a simple script that can run a check and perform an action if the check fails.

cd /root
wget http://downloads.rimuhosting.com/commandchecker.sh

It needs a command to run to test 'something'. In this case that tomcat is running.

Create a /root/istomcatrunning.sh file like this:

#!/bin/bash
tomcatpids=`ps axf --width=200 | grep "\-D[j]ava.endorse" | sed 's/^ *//g' | cut -d ' ' -f 1`
if [ -z "$tomcatpids" ]; then
# return a 'fail' code
return 1
fi
return 0


And it needs a command to run to 'fix' any problem.

Create a /root/restarttomcat.sh file like this:

#!/bin/bash
# try to be nice
/etc/rc.d/init.d/tomcat stop
# but sometimes more drastics measures are necessary if things are not responding
kill -9 `ps axf --width=200 | grep "\-D[j]ava.endorse" | sed 's/^ *//g' | cut -d ' ' -f 1`
/etc/rc.d/init.d/tomcat start


Then just create a job so it runs as needed.

Then create a /etc/cron.d/monitortomcat cron file like this:
0-59/5 * * * * root /root/commandchecker.sh --email youremail@example.com --command "/root/istomcatrunning.sh" --onfail "/root/restarttomcat.sh" --triggeractionafternfails 3 --checkname tomcatcheck > /dev/null

This will check tomcat is running every 5 minutes and restart it if it is down for 15 minutes or more. At least that's the theory. Test it out (e.g. set it up, then stop tomcat and check the script restarts it) and report how it goes.

luciano
09-17-2004, 12:56 PM
Hi,

thanks for your help! Your script is much more professional and feature-complete than mine. I'll test it soon and I'll report how it works.

Thanks again
Luciano

luciano
09-19-2004, 08:50 AM
Hi,

when running your script I get this error:

Command mismatch: /root/daemonitor/istomcatrunning.sh
command: /root/daemonitor/istomcatrunning.sh
hostname: cromoteca.com
date: Sat Sep 18 08:09:01 EDT 2004
checkname: tomcatcheck
expected match:
actual content:

Anyway I found a similar solution within Webmin. I'm new to Webmin so I'm exploring it yet. By looking at the "Other" tab, I found "System and Server Status". There I deleted all unneeded default entries (all except sendmail and xinetd in my case) and added an entry of type "Remote HTTP Service". IMHO that's better than checking for a running process, since Tomcat might be running but not serving pages properly. It happened to me only once, but it happened. I entered the URL http://www.cromoteca.com:8080/ and then I used your "restarttomcat.sh" as command to run if the monitor goes down. Then I enabled the "Scheduled Monitoring" and all tests were fine: now Tomcat seems to be monitored correctly.

Rimu rocks!