Overclockers Australia Forums
OCAU News - Wiki - PC Database - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Other Operating Systems


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 6th September 2009, 8:19 PM   #1
bojo Thread Starter
Member
 
Join Date: Mar 2007
Posts: 1,413
Default [Howto Mythtv] Use a remote to sleep and wakeup a mythtv frontend.

Howdy all.

I spent awhile doing this. Drove me nearly insane, but i found a solution. It's very nice, i hit the power button on my remote and the myth frontend sleeps. Hit it again when it's sleeping and it wakes back up again. Makes the frontend only machine alot more usable for the non-techies in our house .

Steps it took.

1) Enable suspend-to-ram or suspend-to-disk.

Basically here we are just testing if your motherboard can do this. Some can't, some don't resume etc, best to figure it out now, because if your board can't do it, there's not much point in reading the rest of it.

I ended up using pm-suspend to put the machine to sleep.

Basically run

Code:
sudo pm-suspend
in a terminal. (you'll also want to enable this in your bios of course).

Your machine should go into sleep, and you'll probably have to hit the power button to bring it back (or possibly bang on a keyboard/mouse). If all goes well it should resume back into where it was before.

2) Allow the myth user to run pm-suspend without a password

Like all shutdown things, pm-suspend needs to be run by root (or via sudo). This isn't great for your mythtv frontend, typing in a password would be a big hassle!. What we will do, is use visudo to allow the mythtv user to run sudo pm-suspend without being bugged for a password.

In a terminal
Code:
sudo visudo
will open up the default editor and let you muck around with sudo stuff.

Go to the bottom of this file and enter at the very bottom (i think bottom has higher priorites)
Code:
mythtvuser ALL=(ALL) NOPASSWD: /usr/sbin/pm-suspend
now you should be able to type
Code:
sudo pm-suspend
and you won't be asked for a password (NOTE: you might want to wait awhile to test this, as sudo has some kind of memory, so if you just used it, it won't ask again straight away).

3) Enable the remote to wake-up from sleep.

This allows you to use the remote to wakeup the machine.
First enter in a terminal
Code:
cat /proc/acpi/wakeup
This shows you devices etc, and whether they can be used to wakeup the machine. On mine everything was disabled. We want to enable USB (i'm using a usb remote, you may not be) to wake us up from sleep.

Edit /etc/rc.local and add

Code:
sudo sh -c "echo USB0 > /proc/acpi/wakeup"
sudo sh -c "echo USB1 > /proc/acpi/wakeup"
sudo sh -c "echo USB2 > /proc/acpi/wakeup"
sudo sh -c "echo USB3 > /proc/acpi/wakeup"
You may have more of less usb ports here, i just allowed all the numbered usb devices to allow me to wakeup the machine. (you could investigate and figure out the exact one if you wanted).

The reason this is in rc.local, is that /proc/acpi/wakeup seems to be reset each time you boot, so we want to always set it to wakeup from the remote.

Now you can test if you want, run pm-suspend, and the power button on your remote should wakeup your machine .

NOTE: Your remote will do a whole lot of nothing now, lirc doesn't like running from being awakened, we will fix that next

4) Fix lirc's and mythtv's crazyness with sleep.

Mythfrontend doesn't like sleep, neither does lirc. We need to kill them when we sleep, and restart them up again when we come out of sleep.

Luckily, pm-utils has allows us to make our own scripts for sleeping

I made a script in /usr/lib/pm-utils/sleep.d/00mythlirc (the lower numbers are run first on sleep, last one resume).

It contains

Code:
#!/bin/bash

. /usr/lib/pm-utils/functions

case "$1" in
	suspend|hibernate)
		killall mythfrontend.real
		/etc/init.d/lirc stop
		modunload lirc_mceusb2 lirc_dev
		;;

	resume|thaw)
		modreload lirc_mceusb2 lirc_dev
		/etc/init.d/lirc start
		irexec -d
		sleep 2
		sudo -u mythtvuser mythfrontend &
                ;;
esac
You will need to replace lirc_mceusb2 with whatever module your remote uses, and mythtvuser with the user that runs mythfrontend.

The sleep is in there to make sure the network is up, 2 works well for me, but you may need to increase this if it takes longer for your mythmachine to connect to the network (other wise mythtv will ask you about your network settings, as it won't find the backend).

sudo -u mythtvuser just makes sure we run the frontend as the normal mythtv user.

I also have irexec -d in there, as my irexec dissapears when i come out of sleep. (we want to be able to have the machine sleep and resume an infinite amount of times).

5) Allow the remote to put the machine to sleep.

To do this we just need to add in a line to ~/.lirc/mythtv which runs pm-suspend when whatever button is pressed (i used the power button).

Code:
begin
     remote = mceusb
     prog = irexec
     button = Power
     config = sudo /usr/sbin/pm-suspend &
     repeat = 0
     delay = 0
end
mceusb is the remote all my other lirc commands autogenerated with.

I find it best to restart/ logout when you etc the lirc files, there is probably a more elegant way but this works for me.

6) Your finished (hopefully). Now you can power of the myth frontend into sleep when it's not being used, and bring it up reasonably quickly when you need to use it.

I really wish you didn't have to kill mythfrontend when you sleep, as it takes a fairly long time to start, (for me this is from boot or from sleep).

Hopefully that helps someone else who is looking to do this
bojo is offline   Reply With Quote
Old 6th September 2009, 8:23 PM   #2
HyRax1
Furrius Animalus
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 5,200
Default

Nice one! You might want to link this post from the MythTV Wiki.

I've measured the energy consumption of my MythTV backend server to be 17c per day (1.3Kwh consumed every 24 hours), so for $62.05 a year, I personally leave mine on 24/7, but my server also now does torrents and a VM to take advantage of idle time.

Frontend machine(s), however, get switched off when not in use.
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 7th September 2009, 9:06 AM   #3
cleary
with one 'L'
 
cleary's Avatar
 
Join Date: Apr 2003
Location: Griffith NSW
Posts: 1,975
Default

Just fyi, super-user is not needed to suspend the machine (eg since you can do it with a laptop lid close) - you can make use of the Desktop Environment's suspend utility:

Gnome:
Code:
$ gnome-power-cmd
command required: suspend, shutdown, hibernate or reboot
There was a dcop command for kde 3, but kde4 no longer uses it. I found this generic dbus method which should work for most DEs:
http://linux-tipps.blogspot.com/2008...us-in-kde.html
__________________
sidux :: User :: Developer
pcdb :: press
folding :: for SunkenSite
trades :: 100+
cleary is online now   Reply With Quote
Old 20th September 2009, 6:05 PM   #4
g1zmonty
Member
 
Join Date: Jul 2009
Posts: 4
Default Thanks.

This is fantastic Bojo. I went about setting this up this afternoon and it took me very little time to get it working perfectly. Would never have got this working without it.

I was able to skip step 3 entirely as my motherboard was happy to wake up without making any changes (Zotac Ionitx-A).

Thanks!
g1zmonty is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!