The other day I wanted a box doing regular (like, daily) file system backups and really not much else to switch off while idle and then wake up for the next backup. Easy, I thought, install the nvram-wakeup package and that's it.
Alas, nvram-backup mumbled something about an unsupported BIOS that sounded suspiciously like a lot of work that would benefit almost nobody, as the box in question houses an ancient Supermicro board that's probably not very common any more.
So, back to the roots. Essentially any x86 box has an rtc that can wake it up, and Linux has had an interface to that forever: Cat a unix timestamp (serialised to a decimal number) into /sys/class/rtc/rtc0/wakealarm, as discussed in the kernel documentation's sysfs-class-rtc file:
(RW) The time at which the clock will generate a system wakeup event. This is a one shot wakeup event, so must be reset after wake if a daily wakeup is required. Format is seconds since the epoch by default, or if there's a leading +, seconds in the future, or if there is a leading +=, seconds ahead of the current alarm.
That doesn't tell the full story, though. You see, I could do:
BACKUP_AT="tomorrow 0:30" echo `date '+%s' -d "$BACKUP_AT"` > /sys/class/rtc/rtc0/wakealarm
once, and the box came back, but when I then tried it again, the following happened:
echo `date '+%s' -d "$BACKUP_AT"` > /sys/class/rtc/rtc0/wakealarm bash: echo: write error: Device or resource busy
Echoing anything with + or += did not work either; I have not tried to ascertain why, but suspect that's functionality for more advanced RTC chips.
Entering the error message into a search engine did bring up a lkml thread from 2007, but on lmkl.iu.edu the thread ends with an open question: How do you disable the wakealarm? Well: the obvious guess of echo "" does not work. My second guess, however, did the trick: You reset the kernel wakealarm by writing a 0 into it:
echo 0 > /sys/class/rtc/rtc0/wakealarm
– after which it is ready to be written to again.
And now that I've written this post I notice that the 2007 thread indeed goes on, as on narkive, and a bit further down, Tino summed up this entire article as:
Please note that you have to disable the old alarm first, if you want to set a new alarm. Otherwise, you get an error. Example: echo 12345 > /sys/class/rtc/rtc0/wakealarm echo 0 > /sys/class/rtc/rtc0/wakealarm echo 23456 > /sys/class/rtc/rtc0/wakealarm
Ah well. Threading is an important feature in mail clients, even if they're just archives.