[mythtv-users] safe_mythbackend script?

Eni Gma enigma at thedonnerparty.com
Mon Jul 7 21:10:53 EDT 2003


Chris Petersen wrote:

>Has anyone given any thought about writing a safe_mythbackend script
>similar to safe_mysqld?  For those who are unfamiliar, this is basically
>a little shell script that monitors the mysql server and makes sure that
>it's always running.  I've run into times when mythbackend has died
>without my noticing, and it would be nice if it had been able to start
>itself back up again.
>
I use this for my backends:
#!/bin/bash

while [ true ]; do
        /usr/local/bin/mythbackend >> /var/log/myth.log 2>&1 &
        wait $!
        echo "MYTH CRASHED AGAIN! " >> /var/log/myth.log
done



And this for my frontends:
#!/bin/bash

export DISPLAY=localhost:0
SPAWNLIMIT=10
# We'll hang up in here, just for runlevel 4
x=0
while [ true ]; do
        #Start X
        /usr/X11R6/bin/X > /var/log/xout.log 2>&1 &
        echo "X starting:PID $!"
        sleep 5
        /usr/local/bin/blackbox &
        echo "Blackbox starting:PID $!"
        # Don't let screen blank
        /usr/X11R6/bin/xset -dpms s off
        ## Start Myth
        echo "Starting Myth"
        /usr/local/bin/mythfrontend >> /var/log/myth.log 2>&1 &
        MYTHPID=$!
        echo "MythTV started, PID $MYTHPID" >> /var/log/myth.log 2>&1
        echo "Starting Irxevent"
        /etc/init.d/irx start
        # Change virtual terminals to make tv-out work on certain ATI chips
        # Don't do this on the Radeon, it does just fine without it
        #/usr/bin/chvt 1
        #/usr/bin/chvt 7

        wait $MYTHPID
        echo "MYTH DIED, RESTARTING ALL SERVICES"
        /etc/init.d/irx stop

        # Kill the X server (for debugging X problems, probably can be 
commented out)
        pkill blackbox
        pkill X
        # Wait for processes to exit before restarting
        sleep 4
        # Count the number of times we have done this, sleep if we 
respawn too much
        x=$(( $x + 1 ))
        if [ $x -gt $SPAWNLIMIT ]; then
                echo "ERROR: Myth respawing too much, disabling for 10 
minutes"
                sleep 600
                x=0
        fi
done

exit 0

>
>I doubt it would be hard to adapt mysql's script, so maybe I'll poke
>around at it if someone doesn't beat me to it (I'm preparing for my
>in-law's 25th wedding anniversary so it'd be a couple of days).
>
>What do others think about this, though?
>  
>
I run the above scripts from init, so even if the scripts exit or are 
killed it will automatically restart.  I have the following in my 
/etc/inittab:

# Run Myth in runlevel 4
xm:4:respawn:/usr/local/bin/mythinit

This respawns the frontend script above in runlevel 4 (a custom runlevel 
I set up for Myth, most distros don't use 4).  You could just have 
/usr/local/bin/mythfrontend in the above snippet and it would just 
respawn the myth process rather than killing the WM, X and LIRC like my 
script does.

>How robust is mythfrontend if it loses connection with the backend? 
>will it recover if a new instance of the backend reappears?
>  
>
No.  If you are in the menus you can navigate, but once you get to 
something that requires the backend the frontend process will freeze.  


>-Chris
>  
>





More information about the mythtv-users mailing list