/etc/init.d/rc3.d/S99wol:
#!/bin/bash
# At the ASG, create a DNAT for UDP Traffic Port 9 to $DNATDST
# Configuration
MAC=00:26:2d:00:02:6b
NIC=eth0
DNATDST=10.12.28.2
WAFHOST=homeserver.mediavillage.de
# Map Traffic going Fake-IP being flooded broadcasted
ip neigh change $DNATDST lladdr ff:ff:ff:ff:ff:ff nud permanent dev $NIC > /dev/null 2>&1
ip neigh add $DNATDST lladdr ff:ff:ff:ff:ff:ff nud permanent dev $NIC > /dev/null 2>&1
# Monitor Reverse-Proxy and wake up Server if necessary
(
OLD=""
while sleep 1; do
NEW=`awk '/server=\"'"$WAFHOST"'\"/ && /statuscode=\"503\"/ {print }' /var/log/reverseproxy.log | tail -1`
echo $NEW
if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
CURDATE=`date +"%Y:%m:%d-%T"`
CURHOSTNAME=`hostname -f`
CURPID=$$
echo "$CURDATE $CURHOSTNAME [daemon:info] wol[$CURPID]: Wake on WAF: $WAFHOST [$MAC]" >> /var/log/fallback.log
ether-wake $MAC
sleep 180
OLD=$NEW
fi
done
) > /dev/null 2>&1 &
The Script does 2 things at once:
[LIST=1]
- Map an unused internal IP to be the flooded broadcast layer2 address (this is to circumvent ASGs missing possibility to directly DNAT to Broadcast)
- Monitor the WAF Logfile for Connection Timeouts to the Server that should be woken up on demand
The first point is optional and can be commented out if you don't want to be able to wake on WAN any internal host. For this to work you also need to create a DNAT rule via WebAdmin: SRC: Any, SVC: UDP Port 9, DST: External (Address) >> DST: *unused* IP defined in Script. If you don't like that functionality, comment out the two 'ip neigh' lines in the script.
Happy wakeups! [:D]
This thread was automatically locked due to age.