LinHES Forums
http://forum.linhes.org/

How to restart mythfrontend after a crash using your remote!
http://forum.linhes.org/viewtopic.php?f=3&t=2774
Page 1 of 3

Author:  Spektr [ Sun Oct 24, 2004 8:04 pm ]
Post subject:  How to restart mythfrontend after a crash using your remote!

NOTE: this can be used to restart whatever you want, but here I use to to restart mythfrontend ;)

Well, I'm sure all of you at one point in time have had mythfrontend crash on you. It's easy to restart, but if your loved one(s) use your mythtv box, they may not be able to! Well, here is an easy way to be able to use your remote to easily restart mythfrontend! The following will cause a small box to pop up onscreen allowing you so select whether or not you'd like to restart mythfrontend.

Note: I have a Hauppauge PVR-250 remote, if you don't you may have to adjust the buttons accordingly

Without further adue...

We will be using irexec and irxevent to do this, as well as xdialog to make the popup, so first:

Code:
apt-get update && apt-get install lirc-x xdialog


Note, this will move your /etc/lircd.conf to /etc/lirc/lircd.conf, so you will have to copy it back.

Next we have to configure irxevent and irexec to start when X is started, so we add the following lines to /home/.fvwm/.fvwm2rc (this is at the bottom of the file)

Code:
#Remove comment to start irxevents
exec irxevent &
exec irexec &


Also, we want to change the focus model in .fvwmrc to make the popup box come to the front, and focus, so make these changes to the .fvwm2rc file as well:

Comment out
Code:
#ColormapFocus FollowsMouse


and add
Code:
Style * GrabFocus, GrabFocusTransient


Then comment out
Code:
#Style *           FocusFollowsMouse


And save.

With that done, we will now create a simple script to make the popup:

With your favourite editor, create a file (I called mine restartmyth.sh) with the following in it:

Code:
#!/bin/sh

 Xdialog --title "Restart MythTV" --yesno "Would you like to restart
 MythTV?" 0 0

 if [ $? -eq 0 ]
 then
     killall mythfrontend
     mythfrontend &
fi


Then copy it to somewhere in your path...I chose /usr/bin.

Next, give proper permissions to mythtv user, so (as root):

Code:
chown root:mythtv /path/to/yourfilename.sh
chmod 770 /path/to/yourfilename.sh


Next, we want to bind this script to a key on the remote, so edit your /home/mythtv/.lircrc and add these lines:

Code:
begin
   prog = irexec
   button = Go
   config = restartmyth.sh &
end

begin
    prog = irxevent
    button = Ok
    repeat = 0
    config = Key KP_Enter CurrentWindow
end

begin
    prog = irxevent
    button = Vol+
    repeat = 3
    config = Key Right CurrentWindow
end

begin
    prog = irxevent
    button = Vol-
    repeat = 3
    config = Key Left CurrentWindow
end



Note, you can configure the buttons to be whatever you want. Note that I set "GO" to launch this popup dialog, and I set left and right and OK buttons so I can go back and forth and select. Also note that if you bind the left and right keys using irxevent, you will want have to comment out the other left/right keybindings in your .lircrc or else you will be passing the commands twice ;)

Now, save, and reboot...that's it!

Enjoy.

Author:  davem [ Sun Oct 24, 2004 10:41 pm ]
Post subject: 

Nice. :) You'd better go edit the typo above before a newbie hoses his box though. apt-get update, not upgrade! ;)

Author:  Spektr [ Mon Oct 25, 2004 5:37 am ]
Post subject: 

LOL, thanks for catching that, it was pretty late when I wrote that all out ;)

davem wrote:
Nice. :) You'd better go edit the typo above before a newbie
hoses his box though. apt-get update, not upgrade! ;)

Author:  mjvdvlugt [ Mon Oct 25, 2004 9:09 am ]
Post subject: 

Quote:
you will want have to comment out the other left/right keybindings in your .lircrc or else you will be passing the commands twice


Hmm.. does this mean when I use these settings, I can't use the left and right keys anywhere else? That would be a shame because I use them all the time watching tv or dvd's!

Author:  Spektr [ Mon Oct 25, 2004 5:27 pm ]
Post subject: 

Nope, you just don't need duplicates. To briefly explain...if you have, (on hauppauge) Vol+ bound to "Right", and you do what I have laid out above, you have irxevent binding "Vol+" to right as well. So just get rid of any other bindings of Vol+ to right except for irxevent, and it'll work great :) I obviously use the left/right keys a lot for navigation and volume control and whatever else, so I can guarantee that I made sure this was working right ;) If you want to see my .lircrc, or need help with yours, let me know.

mjvdvlugt wrote:
Quote:
you will want have to comment out the other left/right keybindings in your .lircrc or else you will be passing the commands twice


Hmm.. does this mean when I use these settings, I can't use the left and right keys anywhere else? That would be a shame because I use them all the time watching tv or dvd's!

Author:  aelinuxguy [ Mon Oct 25, 2004 5:51 pm ]
Post subject: 

Spektr,

Thanks for this information! I always wanted some way to easily respawn MythFrontend when it crashes. For what it's worth, I did not even really want the dialog asking whether or not to restart the frontend (I was content with the frontend restarting immediately after pressing GO), so I modified restartmyth.sh to be just this:

Code:
#!/bin/sh

killall mythfrontend
mythfrontend &


I'd also chopped down your .lircrc to just this

Code:
begin
   prog = irexec
   button = Go
   config = restartmyth.sh &
end


I suspect for anybody else out there that just wants this immediate respawning, the apt-get would not be neccessary and only the exec lines in the .fvwm2rc would be needed.

Author:  Spektr [ Mon Oct 25, 2004 11:30 pm ]
Post subject: 

aelinuxguy, no problem...you can cut down and edit out a lot of that stuff, but you still DO need to install lirc-x to get irxevent and irexec, from what I could find they aren't install on knopppmyth by default. Therefore you can't cut out the apt-get steps ;) Glad it worked for you :)

aelinuxguy wrote:
Spektr,

Thanks for this information! I always wanted some way to easily respawn MythFrontend when it crashes. For what it's worth, I did not even really want the dialog asking whether or not to restart the frontend (I was content with the frontend restarting immediately after pressing GO), so I modified restartmyth.sh to be just this:

Code:
#!/bin/sh

killall mythfrontend
mythfrontend &


I'd also chopped down your .lircrc to just this

Code:
begin
   prog = irexec
   button = Go
   config = restartmyth.sh &
end


I suspect for anybody else out there that just wants this immediate respawning, the apt-get would not be neccessary and only the exec lines in the .fvwm2rc would be needed.

Author:  mjvdvlugt [ Wed Oct 27, 2004 7:08 am ]
Post subject:  Doubleclick GO to restart frontend

Nice job Spektr!
But I don't want to change the focus options of KnoppMyth. I had problems with focus before (MythTV without KnoppMyth) and now I'm just glad it works. So I couldn't use your method, but I did want the functionality..
Next, I was a bit frightened that by implementing the script of aelinuxguy my girlfriend would keep restarting Mythfrontend accidentally.

So I made my own version! I wanted the frontend to restart only when the GO button is pushed TWICE within 3 seconds.

In /home/.fvwm/.fvwm2rc I added at the bottom:
Code:
exec irxevent &
exec irexec &


Then I changed /home/mythtv/.lircrc to add:
Code:
begin
   prog = irexec
   button = Go
   config = restartmyth.sh &
end


Till now nothing special.

Now the script: restartmyth.sh
Code:
#!/bin/bash

FirstClickFile="/home/mythtv/.FirstClick"
maxClickTime=3

FirstClick() {
 date > $FirstClickFile
 # echo DEBUG: FirstClick!
 exit
}

SecondClick() {
 # If the time between the first and the second click was less than $maxClickTime, restart mythfrontend
 timeSinceLastClick=$(expr $(date +"%G%m%d%H%M%S") - $(date -f /home/mythtv/.FirstClick +"%G%m%d%H%M%S"))

 if [ "$timeSinceLastClick" -lt "$maxClickTime" ]; then
  # echo DEBUG: SecondClick!
  killall mythfrontend
  mythfrontend &
 else
  FirstClick
 fi

 rm -f $FirstClickFile
 exit
}

[ -f "$FirstClickFile" ] || FirstClick
SecondClick

Put restartmyth.sh somewhere in the path (cp restartmyth.sh /usr/bin) and change the permissions (chmod 777 /usr/bin/restartmyth.sh).

As you can see it only restarts Mythfrontend when it's run twice within 3 seconds (A doubleclick on the GO button on the remote). This enables me to restart mythfontend without changing the focus settings, and my girlfriend can't by accident restart it.

I hope this is also usefull to someone else!

Good luck!

Author:  cesman [ Wed Oct 27, 2004 7:59 am ]
Post subject: 

Spektr wrote:
but you still DO need to install lirc-x to get irxevent and irexec, from what I could find they aren't install on knopppmyth by default.
Are you certain?

Author:  mjvdvlugt [ Wed Oct 27, 2004 11:12 am ]
Post subject: 

I did it without the apt-get thing and it works great!

Author:  cesman [ Wed Oct 27, 2004 3:38 pm ]
Post subject: 

mjvdvlugt wrote:
I did it without the apt-get thing and it works great!
I wonder why?! :)

Author:  tjc [ Wed Oct 27, 2004 9:03 pm ]
Post subject: 

cesman wrote:
mjvdvlugt wrote:
I did it without the apt-get thing and it works great!
I wonder why?! :)

My guess would be because some terribly clever knoppmyth developer already included it? Did I guess right? ;-)

On my system with no apt-get::
Code:
root@black:/home/mythtv # locate irexec irxevent
/usr/local/bin/irexec
/usr/local/man/man1/irexec.1
/usr/local/bin/irxevent
/usr/local/man/man1/irxevent.1

Yay!!! I guessed right!!! ;-)

Author:  Spektr [ Wed Oct 27, 2004 11:49 pm ]
Post subject: 

I was too lazy to search for it, and I guess /usr/local/bin wasn't in my path or something, because I wasn't able to find it. In any event, there's no problem with being thorough, I say ;)

On another note cesman, perhaps adding some version of this script to knoppmyth would help. I know the biggest problem I see in mythtv's design is that if the frontend dies and you have no keyboard (and no script such as this)...then you are left to reboot, or ssh in (which only a technical person could do). Just an idea ;)

cesman wrote:
Spektr wrote:
but you still DO need to install lirc-x to get irxevent and irexec, from what I could find they aren't install on knopppmyth by default.
Are you certain?

Author:  Spektr [ Wed Oct 27, 2004 11:53 pm ]
Post subject:  Re: Doubleclick GO to restart frontend

No problem, I like to contribute. Nice job on your script too. Just a few comments...First, as to focus method...the method I use is fully tested and works great...I actually use FVWM for my full-time window manager (http://www.malevolent.net/ss.png for a screenshot of my desktop if you are curious), so I have gotten to know it intimately ;)

Also, you may just want to chown your restartmyth script to mythtv:root and set perms to 774, just to be secure ;)

Cheers

mjvdvlugt wrote:
Nice job Spektr!
But I don't want to change the focus options of KnoppMyth. I had problems with focus before (MythTV without KnoppMyth) and now I'm just glad it works. So I couldn't use your method, but I did want the functionality..
Next, I was a bit frightened that by implementing the script of aelinuxguy my girlfriend would keep restarting Mythfrontend accidentally.

So I made my own version! I wanted the frontend to restart only when the GO button is pushed TWICE within 3 seconds.

In /home/.fvwm/.fvwm2rc I added at the bottom:
Code:
exec irxevent &
exec irexec &


Then I changed /home/mythtv/.lircrc to add:
Code:
begin
   prog = irexec
   button = Go
   config = restartmyth.sh &
end


Till now nothing special.

Now the script: restartmyth.sh
Code:
#!/bin/bash

FirstClickFile="/home/mythtv/.FirstClick"
maxClickTime=3

FirstClick() {
 date > $FirstClickFile
 # echo DEBUG: FirstClick!
 exit
}

SecondClick() {
 # If the time between the first and the second click was less than $maxClickTime, restart mythfrontend
 timeSinceLastClick=$(expr $(date +"%G%m%d%H%M%S") - $(date -f /home/mythtv/.FirstClick +"%G%m%d%H%M%S"))

 if [ "$timeSinceLastClick" -lt "$maxClickTime" ]; then
  # echo DEBUG: SecondClick!
  killall mythfrontend
  mythfrontend &
 else
  FirstClick
 fi

 rm -f $FirstClickFile
 exit
}

[ -f "$FirstClickFile" ] || FirstClick
SecondClick

Put restartmyth.sh somewhere in the path (cp restartmyth.sh /usr/bin) and change the permissions (chmod 777 /usr/bin/restartmyth.sh).

As you can see it only restarts Mythfrontend when it's run twice within 3 seconds (A doubleclick on the GO button on the remote). This enables me to restart mythfontend without changing the focus settings, and my girlfriend can't by accident restart it.

I hope this is also usefull to someone else!

Good luck!
[/url]

Author:  cesman [ Thu Oct 28, 2004 12:09 am ]
Post subject: 

If the frontend or backend dies, it is dying for a reason. While your's is a good idea, it is best to investigate why the death has occured first before restarting the process.

Page 1 of 3 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/