April 22, 2009

Good watchdog for services?

Forums: 

I have a simple script i use to keep track of services running on some of my servers and restart them if they die. Its pretty easy and its dead fast to implement on a server. I wonder if anyone has a simpler/better way than"my" script to watchdog services and restart them as nessecary?

This is what i use now and call on from /etc/crontab once every five minutes or whatever depending on how critical the service is.

server:~ # cat /usr/bin/service-watchdog
#!/bin/bash

MYPROC=programname

COUNT=$(UNIX95=1 ps -C $MYPROC -o pid= -o args= | wc -l) \
if [ $COUNT -lt 1 ]
then
echo "Service xxx is restarting at 'date' >> /var/log/messages
/etc/init.d/servicename restart
else
echo "Service xxx is running."
fi

programname is whatever the process is called
servicename is what the file for starting the service in /etc/init.d is called.

:woohoo: