Intro
This page describes the steps needed to get
ACPI Wakeup running in conjunction with
Mythwelcome on your KM box. Together they will automatically boot your machine prior to a scheduled recording and then shutdown your machine when not in use after a specified time thus saving power and insuring you never miss a show. This of course assumes RTC wakeup alarms are supported in the BIOS of your motherboard. You'll be hard pressed to find a modern motherboard that doesn't support this option. I'm using an old A7N8X-VM that's from 2003 and it works on it.
Using Mythwelcome
As I mentioned, the scripts that drive the shutdown/startup work in conjunction with Mythwelcome which maybe unfamiliar to some users. Here is my nickel tour of mythwelcome:
As you can see, mythwelcome shows some basic info, like data/time, current status of the frontend and in this case a countdown until it shuts the machine off, and the next scheduled recording. It also lets you know if there are any conflicts (although this isn't depicted in the screenshot above), and may display additional info that I haven't seen too.
Aside from starting the frontend like the only button shows, you can also hit the menu button (the M key on the keyboard) if you want to manually force a shutdown, lock the auto shutdown feature or exit to your KM desktop. To me, that lock feature is little redundant since all you need to do is leave your frontend running and none of the auto shutdown stuff will happen -- remember
auto shutdown only happens when mythwelcome is running.
Hit the info button (the I key on the keyboard) if you want to make mythwelcome automatically start your frontend instead of starting itself which will cause it to ignore the auto shutdown option until you manually exit the frontend. I have this set only because if I manually turn the mythbox on, I will very likely be there to hit the "start mythfrontend" button which as I mentioned disables the auto shutdown. I should add that mythwelcome is smart enough to know if other frontend machines on your network are hitting the backend server; in this case, it will not shutdown unless the frontend machine(s) is finished using the backend (i.e. you stop it or place it in its own mythwelcome).
Credit Where Credit is Due
Nearly all the content below came from
fra's post here. Credit also goes to spalVl who helped me get this working with my "fussy BIOS". I merely distilled out the information from these posts (and a few other sources) and put the HOWTO together based on my experience enabling this cool and powerful feature.
Look for RTC Wakeup in Your BIOS
First thing you want to do is see if your BIOS is configured to accept ACPI wakeup commands. Each BIOS is different. Mine for example functions with the RTC Wakeup feature disabled! Look around in your BIOS for a section entitled, "Power Savings" or "Advanced Power Management" etc. for something like, "RTC Alarms" or "RTC Wakeup."
You can set enable it or leave it set to whatever it is currently set to and simply test to see if it works as-is before you actually change the setting. Mine actually requires you to setup a date in the BIOS for it to boot if you enable it; again, I have mine set to "disable" and ACPI Wakeup still works.
Testing ACPI Wakeup Before Modifying Your KM Box
Assuming you have a functional KM install (guide was written and tested with R5F27), test your computer's ability to boot via an RTC alarm from a shell. Simply type:
Code:
$ cat /proc/acpi/alarm
2007-00-00 14:10:00
As you can see, my system returned the current year and GMT current time (since this option is disabled, there is no day or month). Your response may vary. If you get an error here, your hardware likely doesn't support ACPI Wakeup OR you actually have to go into the BIOS and enable the option.
If you did get a response similar to the one I got, setup the box to reboot in say 4 minutes by doing this:
Code:
# echo "2007-12-02 14:14:00" > /proc/acpi/alarm
Obviously, you'll need to substitute the current time and date in your case! Now when you re-cat the /proc/acpi/alarm, it should answer with this time you entered:
Code:
$ cat /proc/acpi/alarm
2007-12-02 14:14:00
Now you just need to shutdown your machine and wait the four minutes. (In case you don't know, you can shutdown via this command):
Code:
# shutdown -h now
If it successfully boots, your BIOS is correctly setup. If unsuccessful, you may need to fiddle with some BIOS settings as described above. If it continues to fail, your hardware might not support this and you can consider using the alternative nvram-wakeup method described on
this wiki page.
Enable MythwelcomeAfter you complete these steps, your box will boot to
Mythwelcome. From there you can start the frontend. For the ACPI wakeup to work, you must exit your frontend and allow mythwelcome to handle everything including manually shutting down your box. If you manually enter a shutdown command, or shutdown the box from the frontend menu, you risk the machine not booting automatically (this depends on whether or not your recording schedule has changed since the last time the shutdown scripts ran).
To setup mythwelcome, simply modify your .fluxbox/apps:
Code:
$ nano /home/mythtv/.fluxbox/apps
And comment out the current line that reads "[startup] {KnoppMyth-run}" simply by putting a number sign (#) in front of it. Now under that line, type the following, "[startup] {mythwelcome}" and save the file (ctrl-x).
Here is what that section in mine looks like for your reference:
Code:
#[startup] {mythfrontend}
[startup] {mythwelcome}
Now we'll configure mythwelcome via this command:
Code:
$ mythwelcome --setup
Make the following changes so it looks like this and then exit:
Code:
nvram-wakeup Command: /usr/bin/setwakeup.sh
nvram-wakeup Restart Command: leave blank
Command to reboot: sudo shutdown -h now
Command to shutdown: sudo shutdown -h now
Command to run Xterm: xterm
Command to run to start the Frontend: KnoppMyth-run
For reference, here is the R5F27 defaults in case you want to revert to them:
Configure Mythtv to RTC Write AlarmsWe'll now make the script that does all the heavy lifting as follows:
Code:
# touch /usr/bin/setwakeup.sh
# nano /usr/bin/setwakeup.sh
You'll need to copy/paste the following into your nano window, then save the script (ctrl-x):
Code:
#!/bin/bash
# Script to set wakeup time using acpi alarm
# Called from mythwellcome:
# first option passed from mythwelcome is --settime second is seconds since 1970
# Convert from stupid time in seconds since 1970
datum=$(/bin/date -d "1970-01-01 UTC $2 sec" +%F\ %T\ %z)
# Reinterpret this in utc and write to alarm
utcdatum=$(/bin/date -u -d "$datum" +%F\ %T)
# Write wakeup time to acpi alarm
echo $utcdatum>/tmp/alarm # Then, /etc/init.d/hwclock.sh is modified to read this file
Now set the permissions and make it a script as follows:
Code:
# chmod +x /usr/bin/setwakeup.sh
# chmod 755 /usr/bin/setwakeup.sh
Modify the hwclock.shNext, we'll modify /etc/init.d/hwclock.sh to make it set the alarm. Before modifying any existing file it is good practice to ALWAYS make a backup in case you mess it up.
Code:
# cp /etc/init.d/hwclock.sh /home/mythtv/hwclock.sh_virgin
Now you can safely edit the live file knowing that you can always restore it from this file you just created.
Code:
# nano /etc/init.d/hwclock.sh
Now do a search (ctrl-w) for a line that contains the phrase:
Code:
clock will not be carried across reboots
Position your cursor UNDER that line and paste in the following:
Code:
ACPITIME=`cat /tmp/alarm`
Notice those aren't quotation marks!
Now do a second search (ctrl-w) for a line that contains the phrase:
Code:
verbose_log_action_msg "Hardware Clock
Position your cursor UNDER that line and paste in the following:
Code:
echo "$ACPITIME" > /proc/acpi/alarm
That should be it. Save the file and exit.
Optional Section - Use only if the Above Doesn't WorkYou may have to also add the following if the above modification doesn't work for you (this has been taken from the "fussy BIOS" section of the
ACPI Wakeup page on the mythtv wiki, and from
spalVl's post here. Again do NOT do it now, but if after you complete the next steps and your mythbox doesn't startup on its own, THEN come back here and add this additional info to your /etc/init.d/hwclock.sh
Again, from with nano, go to the end of your /etc/init.d/hwclock.sh where you should see the following line:
Code:
hwclocksh "$@"
Now directly ABOVE it, paste in the following 15 lines:
Code:
ACPITIME=`cat /proc/acpi/alarm`
if [ "$HWCLOCKACCESS" != no ]
then
if [ "$VERBOSE" != no ]
then
echo "Saving the System /etc/init.d/hwclock.shClock time to the Hardware Clock..."
fi
[ "$GMT" = "-u" ] && GMT="--utc"
/sbin/hwclock --systohc $GMT $BADYEAR
if [ "$VERBOSE" != no ]
then
echo "Hardware Clock updated to `date`."
fi
echo "$ACPITIME" > /proc/acpi/alarm
Now save your file and exit (ctrl-x)
Reconfigure MythtvFirst exit your frontend. Now stop the masterbackend and re-run mythtv-setup:
Code:
$ /etc/init.d/mythtv-backend stop
$ mythtv-setup
Now to go General>5th page and configure as follows:
Blank out your Startup command and place a check in the check box. The next three settings can be whatever you like. These are just what I'm using. The final four settings need to be as described:
Code:
Wakeup time format: yyyy-MM-dd:hh:mm
Set wakeuptime command: sudo mythshutdown --setwakeup $time
Server halt command: sudo mythshutdown --shutdown
Pre-shutdown command: sudo mythshutdown --check
For reference, here is the R5F27 defaults in case you want to revert to them:
Save the settings and exit mythtv-setup.
Now restart your backend with this command:
Code:
# /etc/init.d/mythtv-backend start
Restart X to insure that mythwelcome starts using this command:
Code:
$ pkill xinit
If everything worked right, your machine should have restarted X and you should see Mythwelcome.
That's it!