MythTV has got a lot more stable in recent releases, but I have found that there is still occasional crashes, with MythMusic being the main offender. I have found that if you pause a song as it is just about to end, it invariably hangs and needs to be restarted. To do this I use the “power” button on my remote to kill mythtv, and use another script to automatially restart it.
To kill mythtv you will need irexec installed, then you can add the below to your ~/.lircrc file:
begin
remote = mceusb
prog = irexec
button = KEY_POWER
config = /usr/bin/pkill mythfrontend
repeat = 0
delay = 0
end
So far so good, but we need to make mytvtv restart itself too. I am sure there are many ways of doing this, but I settled on a utility called daemontools. You can install daemontools and daemontools-run from the Ubuntu repositories.
Create an /etc/service/mythfrontend directory, and within that directory create a script called “run”:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MYPROCESS=/usr/bin/mythfrontend
if [ -x $MYPROCESS ]
then
su -c /home/adam/Scripts/startMyth.sh adam
fi
I keep the actual startup script in the scripts directory in my home folder for ease of maintenance – this is the script:
#!/bin/bash export DISPLAY=:0.0 && /usr/bin/mythfrontend \ -l /var/log/mythtv/mythfrontend.log
As soon as you make the /etc/service/mythfrontend/run script executable (chmod +x run), mythfrontend should start. There are some more tips on using daemontools here.
I use a similar script to automatically restart “irexec” if it crashes. Create an /etc/service/irexec directory, with a “run” script:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
if pidof -x /usr/bin/irexec > /dev/null; then
# Do nothing - already running
echo ""
else
su -c /home/adam/Scripts/startIRExec.sh adam
fi
And the startIRExec.sh script:
#!/bin/bash DISPLAY=:0 ~/.local-display-coordinates.sh DISPLAY=:0 irexec
In recent versions of Ubuntu there has been some changes to the way that scripts can connect to the active X session, so the line at the start of this script:
/home/adam/.local-display-coordinates.sh
calls a script that is generated automatically when the X session starts. This is created by adding the following to your ~/.profile script:
case $DISPLAY in :*) export | grep -E ' \ (DISPLAY|XAUTHORITY)=' \ >~/.local-display-coordinates.sh;; esac
This is based on the advice on this page.
