Web Hosting Talk







View Full Version : auto-restart chkservd


Lem0nHead
06-24-2004, 02:53 PM
chkservd is a service that monitors some services and (re)start them in case they stop

the problem is that sometimes chkservd may stop working ;)

so here is a little script to check if it's running and start otherwise:

#!/bin/sh

if [ "`service chkservd status | awk '{print $5}'`" != "running..." ]; then
echo "Restarting chkservd... "
service chkservd restart

echo "chkservd was restarted at `date` on `hostname`" | mail -s "chkservd restarted" root
fi

1) save as /usr/local/bin/chkchkservd.sh (or whatelse you want)
2) edit /usr/local/bin/chkchkservd.sh and change the last word of line 7... it's "root" so it means an E-Mail will be sent to root when it restart... you can put something like "yourname@yourisp.com"
or you can comment this line with a # in the start if you don't want to receive E-Mails (i don't recomment doing that)...
3) chmod 700 /usr/local/bin/chkchkservd.sh
4) crontab -e
5) add */10 * * * * /usr/local/bin/chkchkservd.sh >/dev/null 2>&1

also, i suggest that SIM add some code to monitor chkservd like this one ;)

(i know SIM and chkservd has almost the same function, but i like using both because chkservd checks for cppop too)

Lem0nHead
06-24-2004, 03:45 PM
there's a fix for the script (damn... that's so small and have a bug!):

where you read "service", change for "/sbin/service"