[mythtv-users] Start Mythfrontend if not running?

Kyle Rose krose+mythtv at krose.org
Fri Dec 17 17:36:39 UTC 2004


Here's another approach.  Since I never stop the frontend in my living
room except to reboot it (which I generally do via SSH), I use a
script I hacked up to somewhat intelligently control a program that
crashes at startup (mainly due to transient errors):

krose_run
---------
#! /bin/bash

# === CONFIG START ========================
BLIPCYCLE=30
ROLLDELAY=900
# === CONFIG END ==========================

trap finalize 15

finalize()
{
	if [ "${CHILDPID}" != "" ]; then
		kill ${CHILDPID}
	fi
	exit 0
}

LASTSTART=0
while true; do
	NOW=`date +%s`
	TOOSHORT=$((${NOW}-${LASTSTART} < ${BLIPCYCLE}))
	if [ ${TOOSHORT} = 1 ]; then
		sleep ${ROLLDELAY} &
                CHILDPID=$!
                wait ${CHILDPID}
                CHILDPID=""
	fi
	LASTSTART=`date +%s`
	"$@" &
	CHILDPID=$!
	wait ${CHILDPID}
	CHILDPID=""
done
---------

You then can run any command that should run forever (i.e., until
the krose_run instance is TERM'ed) just by prepending it with
krose_run:

krose_run /usr/local/bin/mythfrontend --verbose playback

and the program will be continually respawned until TERM'ed, but will
wait 900 seconds before the next attempt if the program exits less
than 30 seconds since the last execution.

I use this to run both my backend and frontend: the backend init
script calls krose_run on /usr/local/bin/mythbackend directly, while
the frontend init script calls startx as user mythtv for "start" and
for "stop" relies on a pid file that .xinitrc writes for the krose_run
process that manages mythfrontend.  This way, both backend and
frontend keep respawning until I explicitly stop them with the init
script.

Cheers,
Kyle


Bryan Murphy <bryan at terralab.com> writes:

> This is what I use.  It restarts myth if it crashes, but not if you exit 
> it normally.  Modify to fit your environment.
>
> #!/bin/sh
>
> export DISPLAY=":0.1"
> xset -display :0.1 -dpms
> xset -display :0.1 s off
>
> until [ "$?" == "1" ]; do
>    /opt/MythTV/bin/mythfrontend > /tmp/mythfrontend.log 2>&1
> done


More information about the mythtv-users mailing list