Wake a lan server with NetworkManager
References
Launch scripts based on network location
Arch documentation on NetworkManager
Goal
I want to start my NAS when my desktops are started so I could do some backup and use the global storage (Music, Videos, Pictures...).
How-to
The NAS is ready to accept WOL signal (in the BIOS settings).
To accomplish this task, I am using etherwake on each of my linux boxes.
etherwake -i interface mac_address
This command is encapsulated in a script shell called by the NetworkManager dispatcher. The location is :
/etc/NetworkManager/dispatcher.d/
The script receive two parameters, the interface (eth0 for example) and the status of this interface (up or down).
The command /sbin/ip addr show $IF to $NETMASK return the settings of the network interface $IF if it is within the subnet described with $NETMASK.
Here is the script that I use :
::: bash
#!/bin/sh
# Send a magic packet when an interface comes up, to allow it to start
# the remote server with the MAC address.
set -e
PATH=/sbin:/bin:/usr/sbin
IF=$1
STATUS=$2
MAC=00:11:22:33:44:55
if [ "$IF" = "eth0" ] && [ "$STATUS" = "up" ]; then
#LAN Subnet at home
NETMASK="10.0.0.0/8"
if [ -n "`/sbin/ip addr show $IF to $NETMASK`" ]; then
if [ -e /usr/sbin/etherwake ]; then
/usr/sbin/etherwake -i $IF $MAC
exit $?
fi
fi
fi