Tag Archives: Raspberry Pi

Wake up your computers after a power outage with a Raspberry Pi

raspbian_logo[1]

Even a snazzy networked NUT setup, covering all your windows and linux boxes at home, making sure they all shut down when your over-kill UPS goes into the Low Battery state can seem like a waste of time if you have to come back home and start everything manually before your batcave is back online.

Enter the Raspberry Pi. This is a linux box that will immediately start booting when your power comes back on, assuming you’ve connected it directly to the outlet and not through your UPS. All that’s left is just to wake the rest of your boxes once the Pi’s booted.

In my case I wrote a short script and put it in /usr/local/scripts/wakeEmUp.sh

#!/bin/sh

sleep 600

echo "Waking up everybody"
wakeonlan -f /etc/homeLan.wol

The sleep in there will make sure you won’t start your other computer before a full 10 minutes have passed after the Pi finished booting. this will prevent “flapping”.

/etc/homeLan.wol is a file in the following format:

#
# This an example of a text file containing hardware addresses
#
# File structure
# --------------
# - blank lines are ignored
# - comment lines are ignored (lines starting with a hash mark '#')
# - other lines are considered valid records and can have 3 columns:
#
#       Hardware address, IP address, destination port
#
#   the last two are optional, in which case the following defaults
#   are used:
#
#       IP address: 255.255.255.255 (the limited broadcast address)
#       port:       9 (the discard port)
#

#Computer1
00:11:22:33:44:55

#Computer2
AA:BB:CC:DD:EE:FF

Finally, we need to actually run this when the Pi boots, this can be easily done by adding the invocation to /etc/rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/usr/local/scripts/wakeEmUp.sh &

exit 0