Saturday, July 05, 2008

Saving Energy with Wake-on-LAN

Another tech posting, nothing about leadership today.

I confess: have a lot of computers. Two of them are on full time - one hosts a web site and one hosts a development repository using SVN over an SSH tunnel. After two years of the SVN machine being on 24x7, I wondered if I could put it to sleep and just wake it up when needed. This led me to the Wake-On-LAN feature which was a little harder than I first thought.

First of all, the SVN host is a Apple G5 running 10.4. That matters because I also have the machine set to require a password to access the machine when it wakes up from sleep or screen saver. It turns out that if you remotely wake up your mac under this setting, when the login dialog times out and would normally go back to screen saver, it goes back to sleep mode. I haven't figured out a way to fix this remotely - you would need to login very quickly using VNC or something. The workaround is to never go into sleep mode unless you are at the main login window (you can get there using the "switch user" button or click on the user name in the upper right and then select "login screen"). This realistically prevents me from setting the machine to automaticaly sleep.

Secondly, even though I am providing the ethernet mac address directly in the wakeup utility, the SVN host machine is a gateway and a switch away from the source. I was really frustrated because my laptop running Dirk Lembens' Wake-On-LAN utility would always work, but if I tried a web site or a local linux machine to send the magic wake-on-lan packet, it would only work shortly after the SVN host was put into sleep mode. After thinking about it a bit, I proved that it started to fail when the ARP entry was removed. Only then did I find some resources for the problem.

What I ended up doing is using a perl version of a wake-on-lan utility (runs on OSX as well as linux by the way), and preceded it with an "arp -s" call to seed the ARP cache (I assume Dirk's utility does this also). I stuck the script on the linux box that hosts our web site; my partners can run the script via ssh. So with a simple script to provide the details, they can now wake up the SVN server from anywhere in the world, and I can save a few watts and CO2 in the process.

Only thing left to do is figure out how to remotely put it to sleep. Dirk's utility does this via applescript for Apple machines only, but it doesn't seem to be working for me. Also, this could run into trouble with the problem I mentioned regarding the login timeouts.

No comments: