Wake-on-Lan has been a hot topic lately so here's my two cents.
As always, anything below is provided AS IS and should be fed through
common sense before applying.
First about my set-up -- I have my IP's assigned by DHCP and a dynamically
updated DNS. So when a lease expires the host record is removed from the
DNS.
So my wake-up scheme has to cater for three situations:
1) the machine is up and has a DNS record;
2) the machine is down, but it's lease hasn't expired and thus it still
has a DNS record;
3) the machine is down and has no DNS record.
In case of (1) DNS lookup finds the host, NMB lookup is not attempted,
ping succeeds and backup starts. No need to initiate the wakeup procedure.
In case of (2) DNS lookup finds the host, NMB lookup is not attempted, a
ping would fail so we need to initiate the wakeup procedure before we
ping.
In case of (3) DNS lookup fails, NMB lookup is attempted and would fail,
so we need to initiate the wakeup procedure before that. After NMB lookup
succeeds, ping is attempted before backup starts.
So here's an excerpt from my host 'config.pl':
$Conf{NmbLookupFindHostCmd} = 'wakeup_NmbLookup.sh <MAC> $host';
$Conf{PingPath} = 'wakeup_ping.sh';
$Conf{PingCmd} = '$pingPath <MAC> $host';
$Conf{DumpPreUserCmd} = '/bin/sleep 30';
$Conf{DumpPostUserCmd} = 'bash_shutd.sh $host';
Why the 'sleep 30' before the backup actually starts?
In case of (2), when wakeup is done by the ping command, there's a delay
between when the ping succeeds and when all the necessary services are
started. I didn't' want to hardcode the sleep into my ping script (it's
probably a personal issue :)) so I considered indicator files to count the
times ping script has been called (it's actually called three times) and
also to check if the NMB lookup woke up the computer. But I'm not _that_
impatient.
In case of NMB lookup, I have to wait in the script for the NMB name to
became available (see below).
Here's 'wakeup_NmbLookup.sh':
#!/bin/bash
MAC=$1
HOSTNAME=$2
COUNT=0
# With my configuration, if nmblookup is attempted then the
# host is down for sure. So there is no need to test first whether
# it's actually alive. And if it was, it would only cost me 30 seconds
# of waiting (see below). But one can insert here the first test from
# wakeup_ping.sh (see below).
#
# Send the wakeup-call
/usr/bin/wakeonlan -i <broadcast> $MAC >/dev/null
# We wait... until ping succeeds or we've tried 200 times.
# You can't use 'nmblookup' here, because it exits with 0 even
# if the lookup fails.
/bin/false
until [ $? -eq 0 ]||[ $COUNT -ge 200 ]; do
let "COUNT+=1"
/bin/sleep 2
/bin/ping -c 1 $HOSTNAME > /dev/null
done
# Wait some more for the NetBIOS name to became
# available. See previous comment. Test your set-up to
# find a suitable delay.
/bin/sleep 30
# Output the result of nmblookup for BackupPC to parse
/usr/bin/nmblookup -B <broadcast> $HOSTNAME
exit 0
And here's my ' wakeup_ping.sh':
#!/bin/bash
MAC=$1
HOSTNAME=$2
COUNT=0
# If the test below succeeds, then the computer
# is up and we should output the result of ping
# for BackupPC to parse
if (/bin/ping -c 1 $HOSTNAME > /dev/null); then
/bin/ping -c 1 $HOSTNAME
exit 0
fi
# If the test failed, then we should wake up
# the computer.
/usr/bin/wakeonlan -i <broadcast> $MAC >/dev/null
# We wait... until the ping succeeds, but we only try
# 200 times
# The 'until' loop is better than 'sleep x' here, because
# $Conf{PingCmd} is called three times.
/bin/false
until [ $? -eq 0 ]||[ $COUNT -ge 200 ]; do
let "COUNT+=1"
/bin/sleep 2
/bin/ping -c 1 $HOSTNAME > /dev/null
done
# Output for BackupPC to parse
/bin/ping -c 1 $HOSTNAME
exit 0
So in case of (2) (see above), $Conf{PingCmd} wakes up the computer.
And in case of (3), the $Conf{NmbLookupFindHostCmd} wakes up the computer
and the first test in 'wakeup_ping.sh' succeeds.
To shut down Windows boxen I'm using PowerOff
(http://users.pandora.be/jbosman/applications.html). It has a telnet
interface one can access via an expect script.
Here's my 'bash_shutd.sh':
#!/bin/bash
# This is really a wrapper script, that calls
# an expect script to do the actual shutdown.
# See http://sourceforge.net/mailarchive/message.php?msg_id=15518586
# First check whether automatic shutdown is allowed.
# The blockfile is created via cron to avoid shutting
# down during normal office hours, should the backup
# be still running by that time.
if [ ! -f /backuppc/conf/shutd.block ]; then
# Direct output to /dev/null to protect password
expect_shutd.sh $1 >/dev/null
exit 0
fi
echo "Blockfile exists!"
exit 0
--
R.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
BackupPC-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/backuppc-users
http://backuppc.sourceforge.net/