Difference between revisions of "Frontend Loading Script"

From MythTV Official Wiki
Jump to: navigation, search
(Mythbuntu myth loading script+lirc addition)
(More templating and a sp. fix)
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
= Script =
 
= Script =
 
To avoid having to break out the keyboard and restart mythfrontend, here's a little script I use to restart it automatically:
 
To avoid having to break out the keyboard and restart mythfrontend, here's a little script I use to restart it automatically:
 +
{{Code box|mythrestart.sh|
 
<pre><nowiki>
 
<pre><nowiki>
 
#!/bin/bash
 
#!/bin/bash
Line 8: Line 9:
 
# Automatically restart mythfrontend if it fails.
 
# Automatically restart mythfrontend if it fails.
  
# Just for fun, lets start the myth transcode dameon, too.
+
# Just for fun, lets start the myth transcode daemon, too.
 
sudo mtd -d
 
sudo mtd -d
  
Line 19: Line 20:
 
done
 
done
 
</nowiki></pre>
 
</nowiki></pre>
 +
}}
  
 
Then, instead of starting Myth with 'mythfrontend', start it with the script above.
 
Then, instead of starting Myth with 'mythfrontend', start it with the script above.
Line 28: Line 30:
 
It's also useful when you would like to start mythfrontend remotely (from SSH session for example), and having it forked to background.
 
It's also useful when you would like to start mythfrontend remotely (from SSH session for example), and having it forked to background.
  
 +
{{Code box|startmythfrontend.sh|
 
<pre>
 
<pre>
 
#!/bin/sh
 
#!/bin/sh
Line 59: Line 62:
 
fi
 
fi
 
</pre>
 
</pre>
 +
}}
  
 
== Yet another script ==
 
== Yet another script ==
Line 65: Line 69:
 
It sends all of the frontend's output to the MYTHERRORS file and includes a line if it restarted the frontend after a crash.
 
It sends all of the frontend's output to the MYTHERRORS file and includes a line if it restarted the frontend after a crash.
  
 +
{{Code box|restartfrontend.sh|
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
Line 75: Line 80:
 
done | tee -a ~mythtv/MYTHERRORS
 
done | tee -a ~mythtv/MYTHERRORS
 
</pre>
 
</pre>
 +
}}
  
 
== Mythbuntu oriented script + LIRC support ==
 
== Mythbuntu oriented script + LIRC support ==
Line 82: Line 88:
  
 
The script (I named it 'run_myth')
 
The script (I named it 'run_myth')
 +
{{Code box|run_myth.sh|
 
<pre>
 
<pre>
 
#!/bin/sh
 
#!/bin/sh
Line 98: Line 105:
 
fi
 
fi
 
</pre>
 
</pre>
 +
}}
  
 
My addition to the .lircrc file:
 
My addition to the .lircrc file:
Line 117: Line 125:
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
[[Category:Scripts]]
+
[[Category:Startup Scripts]]

Latest revision as of 11:58, 12 May 2010

There are a few methods to load mythfrontend depending on your setup. This method uses a script that will continually reload mythfrontend if it ever crashes. While technically near impossible to guarantee that mythfrontend will stay running, it should rarely crash and it's more likely that someone will hit ESC too many times and we'll be left with an empty display on our big TV.

Script

To avoid having to break out the keyboard and restart mythfrontend, here's a little script I use to restart it automatically:

Script.png mythrestart.sh

#!/bin/bash
# mythrestart.sh
# Automatically restart mythfrontend if it fails.

# Just for fun, lets start the myth transcode daemon, too.
sudo mtd -d

# Loop the call of mythfrontend.
while [ /bin/true ]
do
        sudo killall mythfrontend
        sudo mythfrontend
        sleep 2
done

Then, instead of starting Myth with 'mythfrontend', start it with the script above.


Alternate Script

Here is a different script I use to start mythfrontend and/or lircd if either quit/crash. The script is launched by irexec whenever I press the 'PC Power' button on my MCE remote.

It's also useful when you would like to start mythfrontend remotely (from SSH session for example), and having it forked to background.


Script.png startmythfrontend.sh

#!/bin/sh
#startmythfrontend.sh
#Start mythfrontend and/or lircd on by remote button press from irexec

if [ "$LOGNAME" == "root" ]
then
        echo "Hello root, you should be running this script as \"mythtv\" user, goodbye."
        exit
fi


if [ ! "$(pidof mythfrontend)" ]
then
        echo "Mythfrontend is not started. Starting Mythfrontend..."
        DISPLAY=:0 xset -dpms
        DISPLAY=:0 mythfrontend > /var/log/mythfrontend.log 2>&1 &
else
        echo "Mythfrontend is already started."

fi


if [ ! "$(pidof irexec)" ]
then
        echo "Irexec is not started. Starting Irexec..."
        DISPLAY=:0 irexec -d /home/mythtv/.lircrc 2&> /home/mythtv/irexec.log 2>&1 &
else
        echo "Irexec is already started."
fi

Yet another script

I wrote this script to be executed from .xinitrc. The idea of the script is to restart the mythtv frontend if it crashes, but if the user chooses to quit, it quits gracefully. There are times when the user may not want the frontend to keep restarting.

It sends all of the frontend's output to the MYTHERRORS file and includes a line if it restarted the frontend after a crash.


Script.png restartfrontend.sh

#!/bin/bash
# This runs mythfrontend until you quit it. if it exits prematurely,
# it will restart it.

while ! /usr/bin/mythfrontend 2>&1
do
      echo `date` ------------- Mythfrontend restarted after a crash
done | tee -a ~mythtv/MYTHERRORS

Mythbuntu oriented script + LIRC support

I updated the 'Alternate Script' to enable me to run mythfrontend from my IR remote when pressing the Start button. It includes an addition to the .lircrc file. It also requires that irexec will be running (maybe by adding it to the auto start list).

The script (I named it 'run_myth')

Script.png run_myth.sh

#!/bin/sh
#run_myth
#Start mythfrontend.
#NOTE: the name of this script MUST NOT include 'mythfrontend'!

if [ ! "$(pgrep mythfrontend)" ]
then
        echo "Mythfrontend is not started. Starting Mythfrontend..."
        DISPLAY=:0 xset -dpms
        DISPLAY=:0 mythfrontend > /home/mythtv/mythfrontend.log 2>&1 &
else
        echo "Mythfrontend is already started."

fi

My addition to the .lircrc file:


begin
        remote = mceusb2
        prog = irexec
        button = Start
        repeat = 0
        config = /home/mythtv/run_myth
end

Note: you can change the button to any button you want. I prefer the Start button in my remote, but your remote could have a different buttons layout/naming.

Other Options

Another option is to have mythfrontend load automatically upon boot, this method is described at Frontend Auto Login