Mythtv Tip: Script to Babysit the Backend

I’ve been running a simple cron task every minute to restart my mythtv backend if it crashes but it wasn’t good enough. I tried using monit but it seems to think the backend is down when it is not and restarts it several times during a recording.

This post from the knoppmyth forums includes a nice script to take care of this along with instructions:

  • If it sees the backend running with a non-defunct process ID, it just exits.
  • If it doesn’t see the backend, and none of the following conditions apply, it’ll re-start it.

  • mythfrontend is down (you’re probably doing some other maintenance)
  • mythbackup is running
  • mythrestore is running

You can easily extend it to add exceptions too.

From a directory such as /tmp, as root:

cp /usr/local/bin
chmod +x /usr/local/bin/


It should exit with no messages, if the backend is running. Otherwise it’ll restart it.

Suggested usage - add this line to crontab:

* * * * * /usr/local/bin/ >>/var/log/mythtv/babysit_backend.log 2>&1