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

Power off via remote?
http://forum.linhes.org/viewtopic.php?f=14&t=17744
Page 1 of 1

Author:  poflynn [ Sun Jan 27, 2008 7:06 pm ]
Post subject:  Power off via remote?

Hi All,

I would like to be able to hit the power button on my remote and have it shut down my front-end. Sounds simple I know..... Lirc etc is working fine & there is a 'Power' button defined in my lircd.conf. I added the lines below to my lircrc file but no joy. I guess it's some kind of auth problem?

Running R5F27. Searched this site, wiki & google with a surprising lack of luck...

Code:
begin
    prog = irexec
    button = Power
    config = /sbin/halt
end


Thanks,

Author:  mjl [ Sun Jan 27, 2008 8:34 pm ]
Post subject: 

Hi,

Just curious as to why you would want to shutdown the fe? I wired my remote to restart the fe any time I hit the green pwr button. Very handy when I accidently get into a keyboard app and then remember I left the keyboard in another room .

Mike

Author:  poflynn [ Sun Jan 27, 2008 9:37 pm ]
Post subject: 

mjl wrote:
Hi,

Just curious as to why you would want to shutdown the fe?
Mike


Jeez, I would have thought it would have been a very common request, but apparently not. I start up the fe, watch a movie for an hour or two and then I want to power it down w/o jumping through all the menus. The be is running 27x7 in the garage. Seems common enough I would have thought.

I hear ya w.r.t. the keyboard app thing but I don't hit that too often and just VNC in when it's that bad. So what's your entry for the restart cmd?

Author:  mjl [ Sun Jan 27, 2008 10:02 pm ]
Post subject: 

Hi,,
Brain cramp on my part. Never occurred to me that you were running a remote fe..

any way, I just add to the .mythtv/lircrc
# Restart Mythfrontend
begin
prog = irexec
button = Power
config = /usr/bin/run-restartmyth.sh &
end

which calls (make executable)
/usr/bin/run-restartmyth.sh
Code:
#!/bin/sh
# Green Power button for FrontEnd restart
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ $(cat /tmp/tv) = "ivtvfb" ]; then
fontsize="26"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
if ps aux | pgrep mythfrontend
then
        #Allow 5 seconds for Lirc to send Escape to MythFrontend
        export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
        export DISPLAY=:0
        echo  "Restarting KnoppMyth Frontend" > /tmp/ver
        cat /tmp/ver | osd_cat --delay=5 --font=$FONT --shadow=2 --color=$fontcolor --pos=bottom --align=centre
        sleep 5
        killall mythfrontend
        mythfrontend &
else
        mythfrontend &
fi


Please note that this not all my code, some is "borrowed" but sadly I didn't mark from whom.

To make it halt I use this: (make executable)
/usr/bin/halt-control
#<code>
#!/bin/bash
# Shutdown mesage
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ $(cat /tmp/tv) = "ivtvfb" ]; then
fontsize="26"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
killall xterm
sudo killall mythfrontend&
echo "Starting Backup, followed with Shutdown" > /tmp/ver
echo "This may take a few minutes...." >> /tmp/ver
export DISPLAY=:0
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
cat /tmp/ver | osd_cat --delay=180 --font=$FONT --color=$fontcolor --shadow=2 --pos=middle --align=centre&
festival --tts /tmp/ver >/dev/null
(play /usr/share/sounds/beg.wav) > /dev/null
sleep 1
sudo /usr/local/bin/mythbackup
killall osd_cat
(play /usr/share/sounds/end.wav)& > /dev/null
sleep 3
sudo halt
#<end code>

You can modify this as needed, change the label in the remote button and call it from the green power.

Mike

Author:  poflynn [ Sun Jan 27, 2008 10:58 pm ]
Post subject: 

mjl wrote:

You can modify this as needed, change the label in the remote button and call it from the green power.

Mike


I did - I made a script file with basically nothing but 'sudo halt' in it ;-) Do I really need all that other stuff? It seems it is all built around the fact that you want to do a backup first.

Thanks for reminding me to make it executable, I'm sure I would have forgotten that, not being a unix-head. Well, this script seems to work. A quick question though, would it be a bad idea to hit this power button while playing a movie or live TV or whatever? Just wondering if 'sudo halt' might force some apps to shut down in a not-so-nice way.

Thanks!

Author:  mjl [ Sun Jan 27, 2008 11:14 pm ]
Post subject: 

Hi,

I'm lazy, could have stripped out all the extra stuff but then you would not have had as much fun :)

Linux shuts down gracefully. From what I understand is when you tell it to end the working day, it goes around and tells everyone else to shutdown their work and then starts the shutdown of the system. Hopefully someone can shed more light.

Mainly when I hit the green button, I want feedback that I pressed the button. The script kills the frontend, kills any xterms I may have open and cleans up as it drops back to the desktop which is pretty obvious that I did press the button. It then tells me what is going to happen as it begins doing a backup and finally shuts down and turns my box off.

The first part just makes it fit on a tv screen if there is one being used.

Hope that was what you were after.
Mike

Author:  poflynn [ Sun Jan 27, 2008 11:21 pm ]
Post subject: 

Good point re. user feedback. Thanks for all of your help, you can go to bed now, it's late ;-)

Thanks!

Author:  jmckeown2 [ Mon Jan 28, 2008 5:10 pm ]
Post subject: 

mjl wrote:
Linux shuts down gracefully. From what I understand is when you tell it to end the working day, it goes around and tells everyone else to shutdown their work and then starts the shutdown of the system. Hopefully someone can shed more light.

For all intents and purposes this is true. Any daemon process gets a chance to go quietly via the init scripts. Eventually if something is hung there will be a chance to go kicking and screaming via a "kill" command and if that fails they get terminated via "kill -kill" User processes are another matter they usually just exit. So, if you've been typing your 600-page Great American Novel, and forgot to save /sbin/halt will result in your editor exiting without ever showing you the "Do you want to save?" dialog. I'm not aware of any Myth front-end problems with exiting in this manner, (maybe MythMusic playlist editing??) If you kill the frontend while streaming from the backend, the backend will figure it out, and move on just fine.

The other command I like is /sbin/shutdown, if you're really concerned about your novel work, 'shutdown -h +5 "Shutdown requested by Green Button Press"' Will send the message to every open XTerm and console window (I think some window managers even display it) The +5 starts a 5 minute countdown. Any time in the 5 minutes you can run (as root) 'shutdown -c' to cancel the shutdown. If you have remote logins and feel like being a BOFH, there's always 'shutdown -h now pblhht\!'

Author:  cecil [ Sat Feb 02, 2008 2:20 am ]
Post subject:  Re: Power off via remote?

Hello,

poflynn wrote:
Code:
begin
    prog = irexec
    button = Power
    config = /sbin/halt
end


Try
Code:
config = sudo /sbin/halt
In place of what you have above.

Author:  Big boy stan [ Sun Feb 03, 2008 12:46 pm ]
Post subject: 

Nice simple solution Cecil. Had it up and working on my FE in about 5 minutes. Also kudos to poflynn for suggesting a solution to a problem that I didnt realize I had :D

Author:  cecil [ Sun Feb 03, 2008 2:44 pm ]
Post subject: 

Simple solutions.... I try. :)

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