Difference between revisions of "Setting A Button On Your Remote To Restart mythfrontend"

From MythTV Official Wiki
Jump to: navigation, search
(New start/restart script written from scratch, note about autostarting irexec)
(added new method)
Line 1: Line 1:
 +
= Method 1 =
 
If you are using a remote control for your mythtv setup via lirc, you may find this helpful.  I don't use mythwelcome yet, so I am running mythfrontend directly as with the pre 0.19 setup.  From the main screen of mythfrontend, it is possible to exit the application, leaving you at the main window in X11/xorg.  So, how do you restart it?  I had found that basically I had to restart X (gdm, kdm, et al.) remotely via ssh since I do not have a keyboard or mouse attached to the machine.  By running irexec, you can use one of the remote buttons to restart mythfrontend.
 
If you are using a remote control for your mythtv setup via lirc, you may find this helpful.  I don't use mythwelcome yet, so I am running mythfrontend directly as with the pre 0.19 setup.  From the main screen of mythfrontend, it is possible to exit the application, leaving you at the main window in X11/xorg.  So, how do you restart it?  I had found that basically I had to restart X (gdm, kdm, et al.) remotely via ssh since I do not have a keyboard or mouse attached to the machine.  By running irexec, you can use one of the remote buttons to restart mythfrontend.
  
Line 48: Line 49:
 
}}
 
}}
  
== A Better Restart Script ==
+
= A Better Restart Script =
  
 
If someone could tell me how to make the progress dialog actually functional, that would be great. For now, this works better than the above, and getting it fully functional is probably very time-intensive, if not impossible (does mythfrontend return anything when it's finished loading and ready for input?).
 
If someone could tell me how to make the progress dialog actually functional, that would be great. For now, this works better than the above, and getting it fully functional is probably very time-intensive, if not impossible (does mythfrontend return anything when it's finished loading and ready for input?).
Line 83: Line 84:
 
</pre>
 
</pre>
 
}}
 
}}
 +
 +
= Auto Login Method =
 +
If you have MythTV set up to automatically login as per the [Frontend Auto Login http://www.mythtv.org/wiki/Frontend_Auto_Login#Method_1] you may just want to '''kill''' mythfrontend so that your system will automatically restart mythfrontend. Good for those random times when myth decides to not play nice and you need to kill it.
 +
 +
What I did was create a new ''system'' lirc file,
 +
{{Code box| /etc/lirc/system|
 +
<pre>
 +
begin
 +
    remote = mceusb
 +
    prog = irexec
 +
    button = Power
 +
    config = /usr/local/bin/restartmythfrontend.sh
 +
    repeat = 0
 +
    delay = 0
 +
end
 +
</pre>
 +
}}
 +
Just change '''remote = mceusb''' as appropriate for your remote, or remove it altogether, and '''button = ''' to whichever button you wish to assign it to.
 +
 +
I then created this Upstart script to launch irexec in daemon mode,
 +
{{Code box| /etc/init/irexec.conf|
 +
<pre>
 +
# irexec
 +
#
 +
# This runs irexec at boot as root with the
 +
# commands in /etc/lirc/system
 +
# Designed for a MythTV 'kill' button on your remote.
 +
 +
start on runlevel [23]
 +
stop on runlevel [!23]
 +
 +
respawn
 +
exec irexec -d /etc/lirc/system
 +
</pre>
 +
}}
 +
 +
Now, if mythfrontend ever gives you trouble, just hit the good ol' ''Kill'' button on your remote and in a few seconds all should be good with the world.
 +
 
[[Category: HOWTO]]
 
[[Category: HOWTO]]

Revision as of 00:03, 30 July 2010

Method 1

If you are using a remote control for your mythtv setup via lirc, you may find this helpful. I don't use mythwelcome yet, so I am running mythfrontend directly as with the pre 0.19 setup. From the main screen of mythfrontend, it is possible to exit the application, leaving you at the main window in X11/xorg. So, how do you restart it? I had found that basically I had to restart X (gdm, kdm, et al.) remotely via ssh since I do not have a keyboard or mouse attached to the machine. By running irexec, you can use one of the remote buttons to restart mythfrontend.

First, create the following script, which could be in your home directory, e.g. /home/mythtv/runmyth:


Script.png /home/mythtv/runmyth

#!/bin/sh
RUNNING=0;

for x in `ps -C mythfrontend | grep -v PID` end; do
    test $x != 'mythfrontend' && continue
    RUNNING=1;
done

if [ $RUNNING = 1 ]; then
    `mythtvosd --bcastaddr="127.0.0.1" \
        --template='alert' \
        --alert_text="MythFrontend is already running" > /dev/null 2>&1 &`
else
    `mythfrontend &`
fi

Make the script executable,

# chmod 700 ~/runmyth.

Next, add the following to your ~/.mythtv/lircrc:


Script.png ~/.mythtv/lircrc

begin
prog = irexec
button = GO
config = ~/runmyth &
end

In my case, I used the GO button on my Hauppauge remote. Note that the script is setup to not allow multiple starts of mythfrontend. It should send a message to the OSD in the event that you hit the GO button while mythfrontend is still running.

For good measure, this is how I run mythfrontend in my X startup. For me, the file is ~/GNUstep/Library/WindowMaker/autostart:


Script.png ~/GNUstep/Library/WindowMaker/autostart

irexec &
~/runmyth &

A Better Restart Script

If someone could tell me how to make the progress dialog actually functional, that would be great. For now, this works better than the above, and getting it fully functional is probably very time-intensive, if not impossible (does mythfrontend return anything when it's finished loading and ready for input?).

Also, a note on autostarting irexec. If you are using mythbuntu, irexec is already installed and will autostart itself as long as there is a valid ~/.lirc/irexec file (tested with version 9.10, may be present in earlier versions).

Script.png ~/Scripts/runmyth.sh

#!/bin/bash
# MythTV auto-start/end script

if [ -z `ps -e -o pid,command | grep mythfrontend | grep -v grep` ]
then
    mythfrontend &
    (for i in $( seq 1 100 )
    do
        echo $i;
        sleep 0.1;
    done) | zenity --auto-close --progress --text="Starting MythTV. This may take longer than this dialog shows." --title="Starting MythTV"
else
    zenity --question --text="Are you sure you wish to exit MythTV?" --tite="Exit MythTV?"
    if [ $? == 0 ]
    then
        for x in $( ps -e -o pid,command | grep mythfrontend | grep -v grep );
        do
            if [ `expr index "$x" "/"` == 1 ]
            then
                continue;
            else
                kill $x;
            fi
        done
    fi
fi

Auto Login Method

If you have MythTV set up to automatically login as per the [Frontend Auto Login http://www.mythtv.org/wiki/Frontend_Auto_Login#Method_1] you may just want to kill mythfrontend so that your system will automatically restart mythfrontend. Good for those random times when myth decides to not play nice and you need to kill it.

What I did was create a new system lirc file,

Script.png /etc/lirc/system

begin
    remote = mceusb
    prog = irexec
    button = Power
    config = /usr/local/bin/restartmythfrontend.sh
    repeat = 0
    delay = 0
end

Just change remote = mceusb as appropriate for your remote, or remove it altogether, and button = to whichever button you wish to assign it to.

I then created this Upstart script to launch irexec in daemon mode,

Script.png /etc/init/irexec.conf

# irexec
#
# This runs irexec at boot as root with the 
# commands in /etc/lirc/system
# Designed for a MythTV 'kill' button on your remote.

start on runlevel [23]
stop on runlevel [!23]

respawn
exec irexec -d /etc/lirc/system

Now, if mythfrontend ever gives you trouble, just hit the good ol' Kill button on your remote and in a few seconds all should be good with the world.