-
-
Save foolsh/8b075a951fb0167c41cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: shell-script -*- | |
# | |
# Control node power through WOL, via `wakeonlan` or `etherwake`. | |
# | |
mac_address={{mac_address}} | |
power_change={{power_change}} | |
ip_address={{node_ip_address}} | |
#if [ -n "${ip_address}" ] | |
#then | |
# iface="$( ip route show to match "{{ip_address}}" | sed -n '/^default/! s/^.* dev \([^ ]*\).*$/\1/p' )" | |
# local_broadcast="$( ip addr show dev "${iface}" | sed -n '/^[[:space:]]*inet/ s/^.* brd \([^ ]*\) .*$/\1/p' )" | |
#fi | |
echo "${power_change} ${ip_address} ${mac_address}" >> /tmp/power | |
if [ "${power_change}" != 'on' ] | |
then | |
#echo "There is no way to power down a node through etherwake." >&2 | |
#exit 1 | |
if [ -n "${ip_address}" ] | |
then | |
#ssh -vv -i /etc/maas/stack-access-key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@${ip_address} -C "echo 'sleep 2 && sudo /sbin/poweroff -f' | at now" >> /tmp/power 2>&1 | |
ssh -i /etc/maas/stack-access-key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@${ip_address} -C "echo 'sleep 2 && sudo /sbin/poweroff -f' | at now" | |
else | |
echo "Unable to power down a node using etherwake without ip address." >&2 | |
exit 1 | |
fi | |
elif [ -x /usr/bin/wakeonlan ] | |
then | |
/usr/bin/wakeonlan -i "192.168.0.255" $mac_address | |
#if [ -n "${local_broadcast}" ] | |
#then | |
# /usr/bin/wakeonlan -i "${local_broadcast}" $mac_address | |
#else | |
# /usr/bin/wakeonlan $mac_address | |
#fi | |
elif [ -x /usr/sbin/etherwake ] | |
then | |
if [ -n "${iface}" ] | |
then | |
/usr/sbin/etherwake -i "${iface}" $mac_address | |
else | |
/usr/sbin/etherwake $mac_address | |
fi | |
else | |
echo "No wakeonlan or etherwake program found." >&2 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment