I’ve a small problem with my mythtv-backend in that it will crash once or twice a week without giving a clue as to the problem, even when running it through gdb.  When restarting, it would work fine again therefore there was the need to detect a crash and restart when it happens.

This is currently been worked on for the next version of Mythbuntu through the use of upstart scripts, however I was needing a soultion before then.  This lead to the development of the script below, which checks to see if it’s running, and restart it if it’s not.

The script is limited in that you need to manually start it after the machine has booted.  I run the script within a screen console (so I can detatch it) using watch to run the script every 60 seconds.

So in screen:

sudo watch -n 60 ./keep-myth-server-alive.sh

The script:

#!/bin/bash

# Copyright (C) 2008
#       David Morris (david.morris@greenacre.no-ip.com)
#
# This program is free software; you can
# redistribute it and/or modify it under the terms
# of the GNU General Public License as published by
# the Free Software Foundation, version 2 or later.
#

if [  `ps -ef | grep -c mythbackend` == '1' ];
then
sudo /etc/init.d/mythtv-backend start

fi

4 Responses to “Keeping mythtv-backend Alive”

  1. Thanks.

    Not had too many problems with my Myth box yet (touch wood) but its nice to know of a simple solution if it does start playing up.

    Jamie.

  2. Randall said

    I’m curious why you chose to use screen and watch instead of just using cron, which would even work across boots.

    You could just put the following in your /etc/crontab:

    * * * * * root /path/to/keep-myth-server-alive.sh >> /path/to/keepalive.log 2>&1

    Or you could use a program like monit.

    Just my 2 cents.

  3. davemorris said

    Cron is the natural selection and your right I should be using it.

    I believe I went with screen and watch since I was using them to test the script, and I simply left them running about 4 weeks ago.

  4. Scott Carlson said

    I’m using monit for this. It works great and monitors MySQL as well.

    http://www.mythtv.org/wiki/index.php/StatusMonitoringHowTo

Leave a Reply