[svlug] Process Watchdog

Tomer tomer at pacbell.net
Mon May 5 09:37:31 PDT 2008


Thanks to everyone that responded! I have compiled below all the tips as a
summary in case someone needs it in the future. I will try the tips and am
sure one or more will work!

================================
#!/bin/bash
pidfile=/var/run/tomcat.pid
for((;;)); do
     if [ ! -f $pidfile ] || ! kill -0 `cat $pidfile`; then
         /etc/init.d/tomcat restart  # or whatever
     fi
     sleep 5
done

If tomcat doesn't create a pidfile, you could do `pidof tomcat` or something
like `ps -e | grep tomcat | head -n 1 | awk '{ print $1 }'` instead.

(If your bash doesn't support 'for((;;))' syntax for some reason, you can
always use 'while true'.)

	-brian

================================

`ps -e | awk '/tomcat/{ print $1 }' | head -n 1`

Or simply:

`pgrep tomcat | head -n 1`

I'm sure someone else knows some awk magic to discard all but the first
match.  Actually, I guess that's not even necessary... passing all the PIDs
to kill should be fine.

	-brian

================================

"man inittab(5)", and see "respawn".

    John
=================================

You can use java service wrapper
http://wrapper.tanukisoftware.org/doc/english/introduction.html#reliability
=================================

Being the lazy cus I am.  I use webmin.  Under the others link, there is
process monitoring that allows you to configure restarts.  It also will mail
you, or sms alert you when it triggers.  I use it for ssh daemons, sendmail
daemons etc.  

James
=================================




More information about the svlug mailing list