A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

April 22, 2009

Good watchdog for services?


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


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

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


Click Here!