Wednesday, December 22, 2010

Watchdog Scripts -don't let daemons die

If you would like to keep certain process/daemons running on a Debian system that you would like for it to be monitored and restarted if it ever stopped you can use supervisor. But I did not find such an application in the default Ubuntu repos hence I started doing some googling and found a simple way to make your own watchdog script for Ubuntu.

First create script that will watch the daemon:
http://www.josehelps.com.pastebin.com/RvXgQ7y1


#!/bin/bash
#Make sure process "YOURPROCESS" is running
pprocess=yourprocessname
runprocess=/user/bin/yourprocessname




if ps ax | grep -v grep | grep $pprocess > /dev/null
        then
                exit
        else
        $runprocess &
        fi
exit

make sure the script is executable:

$chmod 775 nameofscript

then make this script check your process is running every 10 mins, you can set it lower if you like:

$sudo crontab -e


copy and paste this into crontab:


10 * * * *      /home/username/nameofscriptabove


the 10 signifies the time cron should wait until running this job again. The 10 is min the minutes section. 

Hope this helps not letting your precious daemon die when you need them running.

0 comments: