Cron job to check and if needed restart MythBackend

I am running MythTV 0.25 on Fedora 16. The problem I have is that sometimes the backend stops responding for reasons I have not figured out. Until I resolve the problem I want a mechanism that will restart the backend when it stops responding.

The solution I took was to create shell script that would check the backed to see if the service was started and whether it was responding. I have a Cron job that runs every 5 minutes and runs the below script.

The script checks if the backend service is running and if it isn’t then the script assumes you have stopped it on purpose and thus it doesn’t do anything more. If the service is running it then runs “wget” to see if the backend is actually responding. Thus if the service is running but not responding it kills the process and restarts the service.

This script also sends out an email each time it strikes a problem. It also sends an email at the start of every day just saying it has checked and Myth Backend is working.

This script uses “mailx” to send the email direct to your ISPs SMTP server for relaying to the appropriate email address.

Hopefully the rest of the script is intuitive enough and has enough in-line docs to let you figure out the rest.

check_mythtv_and_restart.sh
check_mythtv_and_restart.sh_.zip

If you are looking at how to run a scheduled task or CRON job look at my post:

Gnome Schedule – a GUI to CRON or AT