Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: MythTV: Users

Foolproof Mythbuntu start/restart irexec command

 

 

MythTV users RSS feed   Index | Next | Previous | View Threaded


dheianevans at gmail

Aug 3, 2012, 12:03 PM

Post #1 of 10 (534 views)
Permalink
Foolproof Mythbuntu start/restart irexec command

Head's spinning after Googling this and finding so many different
examples many of which seem to be out of date or specific to different
versions, etc.

Running Mythbuntu 11.04 which does the /notify message/autorestart of
the frontend if it crashes.

I'm looking for a script/command line that will restart the frontend
if it's frozen and start it if it's down. I don't know how to write
bash scripts, but I'm assuming the logic is if it's running "killall
mythfrontend.real" so Mythbuntu can autostart it and if it's not
running then "mythfrontend --service &"

What are you guys doing?
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


joe at thefrys

Aug 3, 2012, 12:29 PM

Post #2 of 10 (502 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

>
> I'm looking for a script/command line that will restart the frontend
> if it's frozen and start it if it's down. I don't know how to write
> bash scripts, but I'm assuming the logic is if it's running "killall
> mythfrontend.real" so Mythbuntu can autostart it and if it's not
> running then "mythfrontend --service &"


How do you define frozen? What would you look at to determine if the
frontend froze?

You could easily create a "restart" button on your remote using irexec...
but to have it happen automagically might be a bit difficult without some
means to identify a frozen frontend.


dheianevans at gmail

Aug 3, 2012, 12:52 PM

Post #3 of 10 (503 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On Fri, Aug 3, 2012 at 3:29 PM, Joseph Fry <joe [at] thefrys> wrote:
>> I'm looking for a script/command line that will restart the frontend
>> if it's frozen and start it if it's down. I don't know how to write
>> bash scripts, but I'm assuming the logic is if it's running "killall
>> mythfrontend.real" so Mythbuntu can autostart it and if it's not
>> running then "mythfrontend --service &"
>
>
> How do you define frozen? What would you look at to determine if the
> frontend froze?
>
> You could easily create a "restart" button on your remote using irexec...
> but to have it happen automagically might be a bit difficult without some
> means to identify a frozen frontend.

That's what I'm talking about, a restart button on the remote with
irexec. And to be clear, what I meant by autostart, I meant that in
Mythbuntu if the frontend crashes, Mythbuntu already starts the
process on it's own and send out a grown notification. That's a
built-in feature.

So right now I have the remote send a killall mythfrontend.real when
_I_ see that the frontend is frozen and mythbuntu then restarts the
frontend. I'm not looking for the Myth box to "identify a frozen
frontend" as I'm doing that manually when it's 3:50pm and the main
screen is stuck hours earlier. :-)

What I need is a way for that same button to check if the frontend is
running at all in case I exited to do some other work at some point
and forgot to start the frontend. Right now we have to VNC in to the
box when that happens.

So again, the logic for the script is "If it's it running, killall
mythfrontend.real (so Mythbuntu then restarts it) and if it's not
running at all start it." but I don't know how to write bash.
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


dheianevans at gmail

Aug 3, 2012, 12:52 PM

Post #4 of 10 (504 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On Fri, Aug 3, 2012 at 3:52 PM, Ian Evans <dheianevans [at] gmail> wrote:
> Mythbuntu if the frontend crashes, Mythbuntu already starts the
> process on it's own and send out a grown notification. That's a
> built-in feature.

grown should growl
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


keemllib at gmail

Aug 3, 2012, 1:36 PM

Post #5 of 10 (504 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On 08/03/2012 02:52 PM, Ian Evans wrote:
...
> So again, the logic for the script is "If it's it running, killall
> mythfrontend.real (so Mythbuntu then restarts it) and if it's not
> running at all start it." but I don't know how to write bash.

Hi;

Run this with the FE running and not running. If the output
matches what you expect, replace the echos with your restart
and start-up commands.

#!/bin/sh

pgrep mythfrontend.real 2>&1 > /dev/null

if [ $? -eq 0 ]; then
echo "Already running, put restart command here."
else
echo "Not running, put your start-up command here"
fi

--
Bill

_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


dheianevans at gmail

Aug 3, 2012, 2:26 PM

Post #6 of 10 (499 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On Fri, Aug 3, 2012 at 4:36 PM, Bill Meek <keemllib [at] gmail> wrote:
> On 08/03/2012 02:52 PM, Ian Evans wrote:
> ...
>
>> So again, the logic for the script is "If it's it running, killall
>>
>> mythfrontend.real (so Mythbuntu then restarts it) and if it's not
>> running at all start it." but I don't know how to write bash.
>
>
> Hi;
>
> Run this with the FE running and not running. If the output
> matches what you expect, replace the echos with your restart
> and start-up commands.
>
> #!/bin/sh
>
> pgrep mythfrontend.real 2>&1 > /dev/null
>
> if [ $? -eq 0 ]; then
> echo "Already running, put restart command here."
> else
> echo "Not running, put your start-up command here"
> fi

Okay so this is the script I made and chmod +x'd

*******************************************************
#!/bin/sh

pgrep mythfrontend.real 2>&1 > /dev/null

if [ $? -eq 0 ]; then
echo "killall mythfrontend.real"
else
echo "mythfrontend --service"
fi
*******************************************************

in my myth lirc file I changed the button command from this:

config = killall mythfrontend.real

to this:

config = /usr/share/mythtv/mythstartrestart.sh

Restarted the system and it doesn't work. Did I do something wrong in
the bash script?
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


thomas at mashos

Aug 3, 2012, 2:30 PM

Post #7 of 10 (498 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On Fri, Aug 3, 2012 at 2:26 PM, Ian Evans <dheianevans [at] gmail> wrote:
> On Fri, Aug 3, 2012 at 4:36 PM, Bill Meek <keemllib [at] gmail> wrote:
>> On 08/03/2012 02:52 PM, Ian Evans wrote:
>> ...
>>
>>> So again, the logic for the script is "If it's it running, killall
>>>
>>> mythfrontend.real (so Mythbuntu then restarts it) and if it's not
>>> running at all start it." but I don't know how to write bash.
>>
>>
>> Hi;
>>
>> Run this with the FE running and not running. If the output
>> matches what you expect, replace the echos with your restart
>> and start-up commands.
>>
>> #!/bin/sh
>>
>> pgrep mythfrontend.real 2>&1 > /dev/null
>>
>> if [ $? -eq 0 ]; then
>> echo "Already running, put restart command here."
>> else
>> echo "Not running, put your start-up command here"
>> fi
>
> Okay so this is the script I made and chmod +x'd
>
> *******************************************************
> #!/bin/sh
>
> pgrep mythfrontend.real 2>&1 > /dev/null
>
> if [ $? -eq 0 ]; then
> echo "killall mythfrontend.real"
> else
> echo "mythfrontend --service"
> fi
> *******************************************************
>
> in my myth lirc file I changed the button command from this:
>
> config = killall mythfrontend.real
>
> to this:
>
> config = /usr/share/mythtv/mythstartrestart.sh
>
> Restarted the system and it doesn't work. Did I do something wrong in
> the bash script?
> _______________________________________________
> mythtv-users mailing list
> mythtv-users [at] mythtv
> http://www.mythtv.org/mailman/listinfo/mythtv-users

Have you tried enabling the "Generate frontend restart mapping"
checkbox in the Mythbuntu Control Centre? It makes restarting the
frontend mapped to pressing Power followed by Clear.

Thanks,

Thomas Mashos
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


newbury at mandamus

Aug 3, 2012, 2:34 PM

Post #8 of 10 (499 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On 08/03/2012 03:52 PM, Ian Evans wrote:

>
> So again, the logic for the script is "If it's it running, killall
> mythfrontend.real (so Mythbuntu then restarts it) and if it's not
> running at all start it." but I don't know how to write bash.

This is what I use:

############### startfrontend.sh script

#/!/bin/bash
export HOME=/home/mythtv/
export DISPLAY=:0.0
export PROG=mythfrontend

STATUS=0
# check for running mythfrontend
STATUS=`ps -ae | grep $PROG | grep -v grep | wc -l | awk '{print $1}'`
export STATUS
#echo "STATUS = "$STATUS
if [ $STATUS -eq 0 ];
then
# Start mythfrontend: play a tone to announce it is working
/usr/bin/mplayer /usr/share/sounds/KDE-Im-Contact-In.ogg

/usr/local/bin/mythfrontend --display $DISPLAY -v playback -l
/var/log/mythfrontend.log &
sleep 3
killall startfrontend.sh;
else
# kill all running mythfrontends: use different announcement tone
/usr/bin/mplayer /usr/share/sounds/KDE-Im-Contact-Out.ogg
killall mythfrontend
killall startfrontend.sh;
fi
exit 0

########################

You need this stanza in your lircrc file:


# ****************** section needed in lircrc
# -------------- Begin section for irexec ------------------

# Red button on old remote
# Small 'power' button on Harmony remote, starts mythfrontend
begin
prog = irexec
button = KEY_EXIT
repeat = 2
config = /usr/local/sbin/startfrontend.sh
end
## -------------- End section for irexec --------------------

# *********************************************

You will have to fiddle around a little to find the right key name. The
KEY_EXIT key here, is the small power key on the righthand side of a
Logitech Harmony 330 *talking to an iMon remote receiver*. It's really
the receiver which determines the output key-code you get from lirc, so
you may have to play with irw or irrecord to see what keys map to in
terms of their naming. In this case, you want the key to be mapped ONLY
to irexec since it never gets 'focus' like an mplayer or mythtv screen
instance.

And finally, you need to have irexec running
You can call the /usr/bin/irexec line in /etc/rc.d/rc.local or whatever
runs last, In Fedora with systemd, there seem to be problems with that,
so I just tacked the call into the bottom of the start{ stanza of
/etc/rc.d.init.d/lirc so it is always called/started whenever the lirc
service is started. (And I stop it in the stop{ stanza with a killall)


# ******************** section in rc.d/init.d/lirc
# bottom of start{ stanza
/usr/bin/irexec -d /etc/lirc/lircrc
return $retval
}

##################

Together this works like a charm.


HTH

Geoff
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


dheianevans at gmail

Aug 3, 2012, 2:45 PM

Post #9 of 10 (502 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

On Fri, Aug 3, 2012 at 5:30 PM, Thomas Mashos <thomas [at] mashos> wrote:
> Have you tried enabling the "Generate frontend restart mapping"
> checkbox in the Mythbuntu Control Centre? It makes restarting the
> frontend mapped to pressing Power followed by Clear.

Wow, ok, so that was ridiculously easy to do. I've never really
bothered with Mythbuntu Control Centre before and didn't know that was
there. I also like the two button approach because it makes an
accidental press a thing of the past especially as power and clear are
at two ends of the remote!

Now I can reclaim that button for something else.
_______________________________________________
mythtv-users mailing list
mythtv-users [at] mythtv
http://www.mythtv.org/mailman/listinfo/mythtv-users


joe at thefrys

Aug 3, 2012, 2:49 PM

Post #10 of 10 (505 views)
Permalink
Re: Foolproof Mythbuntu start/restart irexec command [In reply to]

>
>
> > So again, the logic for the script is "If it's it running, killall
>
>> mythfrontend.real (so Mythbuntu then restarts it) and if it's not
>> running at all start it." but I don't know how to write bash.
>>
>
> Hi;
>
> Run this with the FE running and not running. If the output
> matches what you expect, replace the echos with your restart
> and start-up commands.
>
> #!/bin/sh
>
> pgrep mythfrontend.real 2>&1 > /dev/null
>
> if [ $? -eq 0 ]; then
> echo "Already running, put restart command here."
> else
> echo "Not running, put your start-up command here"
> fi


This should work for the entire thing, just create the necessary rcexec
entry with this command, no script necessary (untested in rcexec):

pidof mythfrontend.real && killall mythfrontend.real || mythfrontend &

I know it looks weird, but it really does work.

Boolean logic doesn't process any more than it has to in Bash... so in an
AND... if the left is false, then it doesn't check the right; in an OR, if
the left is true it doesn't check the right.

And Bash lets you use application exit codes as the values you your logic.
So this basically replicates and if then else structure in one line.

MythTV users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.