I’ve recently been toying with the idea of setting up a schedule for my home servers to be up. As the only time I really use them is whilst at work (to stream music from), I considered a simple script to power them down at a set time (18:00), and power it up before I head to work. The problem is, I have a terrible memory, so I’m likely to forget to power the server up on the way out the door. Another solution was needed…
Most servers, and desktops for that matter, come with a feature called “Wake-On-LAN”, or “WOL” for short. This is a feature that allows the network card to be listening to traffic on the interface whilst the actual server is off. Then, using a specially crafted packet called a “Magic Packet”, a command is triggered on the motherboard to power the server on. All I needed to do from here was setup a port on my gateway to forward the magic packet from outside the network, to the internal machine. This would allow me to trigger remote start-ups.
From my Debian server, I installed the wakeonlan package so I could trigger remote startups. This was a case of simply issuing an apt-get:
apt-get install wakeonlan
You can then use it to trigger a startup…
wakeonlan -i 22.214.171.124 AA:AA:AA:AA:AA:AA
This would send the magic packet to the IP 126.96.36.199, looking for the MAC AA:AA:AA:AA:AA:AA.
Then there is the matter of powering down. As I usually leave work around 17:30, I set the powerdown for 18:00. This was a simple cron job…
0 18 * * 1,2,3,4,5 /sbin/halt
It’s pretty cool to be able to type a command in one state (SSH’d to a server at a remote location), and hear the server under your desk power up.