Das Testsignal selbst ist eine while-Endlosschleife von nslookup-Befehlen. Vor der while-Schleife wird eine temporäre Datei für die nslookup-Antworten eingerichtet. Die Variablen probefail und retries werden auf 0 initialisiert.
# Set up a temporary file for the nslookup replies. DNSPROBEFILE=/tmp/.$RESOURCE_NAME.probe probefail=0 retries=0
Die while-Schleife führt folgende Aufgaben durch:
Festlegen des Ruheintervalls für das Testsignal
Verwenden von hatimerun zum Starten von nslookup, Übergeben des Wertes Probe_timeout und Identifizieren des Ziel-Hosts
Festlegen der probefail-Variablen, basierend auf dem Erfolg oder Fehlschlag des nslookup-Rückgabecodes
Wenn probefail auf 1 (Fehlschlag) eingestellt ist, wird überprüft, ob die Antwort auf nslookup vom Beispieldatendienst und nicht von einem anderen DNS-Server kam.
Es folgt der while-Schleifencode.
while :
do
# The interval at which the probe needs to run is specified in the
# property THOROUGH_PROBE_INTERVAL. Therefore, set the probe to sleep
# for a duration of THOROUGH_PROBE_INTERVAL.
sleep $PROBE_INTERVAL
# Run an nslookup command of the IP address on which DNS is serving.
hatimerun -t $PROBE_TIMEOUT /usr/sbin/nslookup $DNS_HOST $DNS_HOST \
> $DNSPROBEFILE 2>&1
retcode=$?
if [ $retcode -ne 0 ]; then
probefail=1
fi
# Make sure that the reply to nslookup comes from the HA-DNS
# server and not from another nameserver mentioned in the
# /etc/resolv.conf file.
if [ $probefail -eq 0 ]; then
# Get the name of the server that replied to the nslookup query.
SERVER=` awk ' $1=="Server:" { print $2 }' \
$DNSPROBEFILE | awk -F. ' { print $1 } ' `
if [ -z "$SERVER" ]; then
probefail=1
else
if [ $SERVER != $DNS_HOST ]; then
probefail=1
fi
fi
fi