Many MythTV users leave their backend (recording) servers running 24X7 and only power their front ends on and off. Being of a green disposition I wanted to avoid this, as even the best computers consume a reasonable amount of electricity just sitting there. There are various options available under Linux to wake your machine up from a sleep state.
The normal way of getting MythTV to power up the machine on a recording schedule is to use nvram-wakeup Shutdown Wakeup. However I was not very happy with this as direct poking of the systems Non Volatile RAM seems very dangerous to me, plus it involves a lot of messing around with custom kernels etc. Plus it just did not work for my ECS Mother Board.
Advanced Configuration and Power Interface (ACPI)
The PC Industry have been moving from the older APM power managment specification to the newer ACPI specification. ACPI for Linux is under heavy development but is already quite useable with the 2.6 kernel.
I have chosen to go with using ACPI to have my MythTV box wakeup while I am away , record a programme and then power itself back down. You will find the ACPI features for your machine exposed as a collection of files and directories in /proc/acpi. For instance /proc/acpi/alarm is a file that corresponds to the Real Time Clock wakeup function on your machine.
Note: Testing this on kernel 2.6.17-gentoo-r4 and r7, revealed that you will only have this option on x86_64 architecture. The setup of /proc/acpi/alarm is done in kernel file drivers/acpi/sleep/proc.c and controlled by the CONFIG_ACPI_SLEEP_PROC_FS flag. You can test support for you architecture by going to you kernel source and do:
$grep -r CONFIG_ACPI_SLEEP_PROC_FS arch/* arch/x86_64/defconfig:CONFIG_ACPI_SLEEP_PROC_FS=y
Note 2: To enable acpi-sleep in the kernel, it is necessary to set "Support for hot-pluggable CPUs" ( Processor type and features ---> [*] Support for hot-pluggable CPUs) so that (CONFIG_HOTPLUG_CPU=y). After this it is possible to set ([*] Sleep States) under ACPI support
Basic IO System (BIOS)
You will need to have a motherboard that supports both ACPI and a Real Time Clock Alarm Functions in the BIOS. Dont forget to enable this in the BIOS. You will find a tab similar to "Advanced Power management".
On a via epia EN15000 board you need to -disable- the Wake on RTC in the BIOS for the ACPI way to work. One observation is that only then does a programmed Wake on RTC also survive a reboot, otherwise it keeps getting reset. This might be an clue to others in the same situation.
Testing ACPI Wakeup Works
Here are the commands to check that you have ACPI working.
$powersave -S ACPI
Check that you have the alarm function in /proc/acpi/alarm. This prints out the RTC Alarm clock from the BIOS.
$cat /proc/acpi/alarm 2005-**-29 10:10:04
Check that you can write a new time to the RTC Clock Alarm (you will need to be Root) Format is YYYY-MM-DD HH:MM:SS
#echo "2005-12-29 10:10:04" >/proc/acpi/alarm
Check that it was written, shut down and wait for it to wakeup.
#cat /proc/acpi/alarm 2005-*12-29 10:10:04 #shutdown -h now
(note you may not see the change in the bios, but it should still work)
Now go to your MythBackend Configuration and setup wakeup and shutdown. If you don't have a script you want to run before shutdown, insert 'exit 0' in the field for the command before shutdown, otherwise automatic shutdown will not work.
Getting autostart using alarm can be quite frustrating. Here's some tips on getting it working.
UTC Bios Clock
Remember, your bios time might be in UTC rather than local time using:
# echo "+00-00-00 00:05:00" > /proc/acpi/alarm
will set the wakeup time to 5 minute from now, regardless of whether the RTC is in UTC or locatltime.
Since the wake-up time given by mythtv to the mythtv wakeup command is in local time, you need to do some bash handling of the obtained time to be able to setup the wakeup time in the bios in UTC (independent of daylight savings time and such). The following bash code might help here:
#!/bin/bash stamp_file=/home/mythtv/timestamp echo $1\ $2 > $stamp_file # If using mythwecome you can try the next line instead on the one above. #echo $1 | sed "s/T/ /" >$stamp_file # Read the date in the locale time format and add the time-zone info to the stamp_file datum=$(/bin/date -f $stamp_file +%F\ %T\ %z) echo $datum > $stamp_file # reinterpret this in utc and write to alarm utcdatum=$(/bin/date -u -f $stamp_file +%F\ %T) echo $utcdatum > $stamp_file #rm -f $stamp_file #echo $utcdatum >/proc/acpi/alarm
As you noticed the echo to the acpi-alarm is commented out by default, because it is really better to check first if everything is working correctly (time format the same on your bios and such).
Some motherboard bioses are extremely fussy when setting the wake up alarm. These bioses refuse to wake up if the hardware clock is modified after the alarm timer has been set. Most linux distributions do this by default when shutting down (they write the current system time back to the hardware clock). This causes the system never to wake up.
Hence check your shutdown scripts!
Under ubuntu/debian modifying
/etc/init.d/hwclock.sh with the following will fix this problem:
stop|restart|reload|force-reload) ==> ACPITIME=`cat /proc/acpi/alarm` if [ "$HWCLOCKACCESS" != no ] then if [ "$VERBOSE" != no ] then echo "Saving the System Clock 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
Under Fedora Core 6 modifying
/etc/init.d/halt with the following will fix this problem:
==> ACPITIME=`cat /proc/acpi/alarm` [ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS ==> echo "$ACPITIME" > /proc/acpi/alarm
Fussy Bios II
For some motherboards, like the MS-6760 (MSI MEGA 651), it is required that you set the wakeup time two times, otherwise it will not wake up.
#echo "2005-12-29 10:10:04" >/proc/acpi/alarm && sleep 1 && echo "2005-12-29 10:10:04" >/proc/acpi/alarm
Another possible glitch is, that the option 'Resume By Alarm' (or whatever it is called) is set to Enabled but wake up using
/proc/acpi/alarm only works if the option is set to Disabled. Sounds weird but works with some boards.