Difference between revisions of "Putting mythfrontend to sleep"
(How to add a functional "Sleep" menu item to the main mythfrontend menu.) |
|||
Line 9: | Line 9: | ||
The main reason I didn't run all of MythTV on one machine is that our "TV room" is also our bedroom, and all the hardware I had on hand was unacceptably noisy for trying to sleep. Mythbackend needs stay on all the time (or turn itself on and off as needed, as per this excellent How To article on [[ACPI Wakeup]]), but we needed to be able to shut down the machine running mythfrontend in order to get to sleep at night. | The main reason I didn't run all of MythTV on one machine is that our "TV room" is also our bedroom, and all the hardware I had on hand was unacceptably noisy for trying to sleep. Mythbackend needs stay on all the time (or turn itself on and off as needed, as per this excellent How To article on [[ACPI Wakeup]]), but we needed to be able to shut down the machine running mythfrontend in order to get to sleep at night. | ||
− | I haven't yet bought a fancy IR remote control yet, either, so currently we use a regular keyboard at the end of three USB extension cords. We could shot the computer down just fine by selecting "Exit and Shutdown" from the pop-up menu on the main screen, but once it was off, we'd have to walk over to the tower computer itself to press the "On" button. I decided that what we really needed was a new option on the main MythTV menu: "Sleep." (If I ever get a remote control, I'll revise this article to explain how to use the "Power" button of the remote to sleep/wake the PC instead of having a menu option, I hope!) | + | I haven't yet bought a fancy IR remote control yet, either, so currently we use a regular keyboard at the end of three USB extension cords. We could shot the computer down just fine by selecting "Exit and Shutdown" from the pop-up menu on the main screen, but once it was off, we'd have to walk over to the tower computer itself to press the "On" button. I decided that what we really needed was a new option on the main MythTV menu: "Sleep." (If I ever get a remote control, I'll revise this article to explain how to use the "Power" button of the remote to sleep/wake the PC instead of having a menu option, I hope!) |
+ | |||
+ | I installed MythTV v0.22 on an existing Ubuntu system for the backend server, and installed Mythbuntu v0.22 off a CD from the .iso image for the front end machine, but this article should apply to many other configurations as well, although I'm sure some of the file locations will wander about depending on the version of MythTV and/or Linux that you're running. | ||
= The Solution = | = The Solution = | ||
+ | |||
+ | If I could get the machine to just go to sleep, then it ought to be as good as shutting it off for when we were trying to go to sleep ourselves, but we'd be able to start it back up a lot faster than we could with a full boot-from-off sequence, and it should be possible to wake it up just by poking a key on the keyboard instead of having to walk over to the computer itself. If I just quit from mythfrontend on my tower PC, I would get dropped onto the default graphic UI for Mythbuntu, which I believe is Xfce. From here, choosing to log out brought up a fancy window that offered me the choices of logging out, restarting, shutting down, suspending, or hibernating the system. I wasn't even sure what the last two options actually did, although they definitely sounded like what I was looking for. | ||
+ | |||
+ | A bit of research revealed the difference. "Suspend" was what I generally thought of as "sleep," in that the computer would power down most of its systems but would keep a trickle of power to the RAM so that it could wake up and pick up where it left off when nudged. "Hibernate" is almost the same thing, except that the operating state is saved onto the drive. If I understand what I've read, this takes even less power, since the computer doesn't maintain the RAM state, and it means the machine can "wake up" even if the power is interrupted, but it takes longer to shut down and to wake up, since there's disk activity on both state changes. I didn't see any benefit to being able to wake up even after a power failure, and "Hibernate" was notably slower than "Suspend," so that's what I decided to shoot for. | ||
== Step One: Waking Up From the Keyboard == | == Step One: Waking Up From the Keyboard == | ||
+ | |||
+ | Unfortunately, the first problem showed up right away. I could certainly Suspend or Hibernate the system just fine, but once it was asleep, the only way to wake it back up was . . . to press the "Power" button on the case. The [[ACPI Wakeup]] article was very useful in giving me the clues I needed, and further research on the ACPI system explained how to tell the system to watch the USB bus for activity, and wake up when it saw some. The key was this command: <pre> echo "USB0" > /proc/acpi/wakeup</pre> | ||
+ | |||
+ | Although "wakeup" appears to be an ordinary file, this command does ''not'' simply overwrite the contents with "USB0" as I expected. Instead, it somehow toggles the "disabled" flag in that file to "enabled." My version of the file had both "USB0" and "USB1," and I figured I'd just enable both rather than trying to figure out which one the keyboard was in, and then having to worry about somebody moving the plug to the other bus and disabling the keyboard wakeup ability. | ||
+ | |||
+ | Alas, it's more complicated than that, since the flags switch back to "disabled" whenever the system reboots . . . or wakes from sleep. So a script that re-enables them every time the machine wakes up is required. This means getting involved with the "init.d" system. First, a script is needed to enable waking from USB activity. | ||
+ | {{Code box|wake.sh|<pre>#!/bin/bash | ||
+ | |||
+ | echo "USB0" > /proc/acpi/wakeup | ||
+ | echo "USB1" > /proc/acpi/wakeup</pre>}} | ||
+ | |||
+ | I think I could have stick with the traditional "#!/bin/sh" at the top if I'd used "/bin/echo" instead of just "echo," but this worked, so I haven't bothered changing it. Then the script needs to be made executable, and put where the init.d system can find it. <pre>chmod +x wake.sh | ||
+ | cp wake.sh /etc/init.d/</pre> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
[[Category:HOWTO]] | [[Category:HOWTO]] |
Revision as of 22:36, 27 January 2010
This "How To" article pulls together a number of different aspects of customizing MythTV, to accomplish what would seem to be a simple task: putting your MythTV system to sleep.
Introduction
One very common MythTV configuration is to have one machine running both mythfrontend and mythbackend on a custom-assembled, small, quiet machine sitting with the rest of the A/V equipment. I couldn't afford to buy a new computer for MythTV, but I have a lot of computers sitting around the house, so I set up MythTV on two computers. Mythbackend is running on a fairly powerful and very noisy rack-mount server that hangs out with the other noisemakers in the basement. Mythfrontend is running on a PC that I inherited that used to run Windows in an office.
The Problem
The main reason I didn't run all of MythTV on one machine is that our "TV room" is also our bedroom, and all the hardware I had on hand was unacceptably noisy for trying to sleep. Mythbackend needs stay on all the time (or turn itself on and off as needed, as per this excellent How To article on ACPI Wakeup), but we needed to be able to shut down the machine running mythfrontend in order to get to sleep at night.
I haven't yet bought a fancy IR remote control yet, either, so currently we use a regular keyboard at the end of three USB extension cords. We could shot the computer down just fine by selecting "Exit and Shutdown" from the pop-up menu on the main screen, but once it was off, we'd have to walk over to the tower computer itself to press the "On" button. I decided that what we really needed was a new option on the main MythTV menu: "Sleep." (If I ever get a remote control, I'll revise this article to explain how to use the "Power" button of the remote to sleep/wake the PC instead of having a menu option, I hope!)
I installed MythTV v0.22 on an existing Ubuntu system for the backend server, and installed Mythbuntu v0.22 off a CD from the .iso image for the front end machine, but this article should apply to many other configurations as well, although I'm sure some of the file locations will wander about depending on the version of MythTV and/or Linux that you're running.
The Solution
If I could get the machine to just go to sleep, then it ought to be as good as shutting it off for when we were trying to go to sleep ourselves, but we'd be able to start it back up a lot faster than we could with a full boot-from-off sequence, and it should be possible to wake it up just by poking a key on the keyboard instead of having to walk over to the computer itself. If I just quit from mythfrontend on my tower PC, I would get dropped onto the default graphic UI for Mythbuntu, which I believe is Xfce. From here, choosing to log out brought up a fancy window that offered me the choices of logging out, restarting, shutting down, suspending, or hibernating the system. I wasn't even sure what the last two options actually did, although they definitely sounded like what I was looking for.
A bit of research revealed the difference. "Suspend" was what I generally thought of as "sleep," in that the computer would power down most of its systems but would keep a trickle of power to the RAM so that it could wake up and pick up where it left off when nudged. "Hibernate" is almost the same thing, except that the operating state is saved onto the drive. If I understand what I've read, this takes even less power, since the computer doesn't maintain the RAM state, and it means the machine can "wake up" even if the power is interrupted, but it takes longer to shut down and to wake up, since there's disk activity on both state changes. I didn't see any benefit to being able to wake up even after a power failure, and "Hibernate" was notably slower than "Suspend," so that's what I decided to shoot for.
Step One: Waking Up From the Keyboard
Unfortunately, the first problem showed up right away. I could certainly Suspend or Hibernate the system just fine, but once it was asleep, the only way to wake it back up was . . . to press the "Power" button on the case. The ACPI Wakeup article was very useful in giving me the clues I needed, and further research on the ACPI system explained how to tell the system to watch the USB bus for activity, and wake up when it saw some. The key was this command:echo "USB0" > /proc/acpi/wakeup
Although "wakeup" appears to be an ordinary file, this command does not simply overwrite the contents with "USB0" as I expected. Instead, it somehow toggles the "disabled" flag in that file to "enabled." My version of the file had both "USB0" and "USB1," and I figured I'd just enable both rather than trying to figure out which one the keyboard was in, and then having to worry about somebody moving the plug to the other bus and disabling the keyboard wakeup ability.
Alas, it's more complicated than that, since the flags switch back to "disabled" whenever the system reboots . . . or wakes from sleep. So a script that re-enables them every time the machine wakes up is required. This means getting involved with the "init.d" system. First, a script is needed to enable waking from USB activity.
I think I could have stick with the traditional "#!/bin/sh" at the top if I'd used "/bin/echo" instead of just "echo," but this worked, so I haven't bothered changing it. Then the script needs to be made executable, and put where the init.d system can find it.chmod +x wake.sh cp wake.sh /etc/init.d/