探測本身是 nslookup 指令的一個無窮 while 迴圈。在 while 迴圈之前,將會設定一個暫存檔以存放 nslookup 回覆。probefail 和 retries 變數均初始化為 0。
# Set up a temporary file for the nslookup replies. DNSPROBEFILE=/tmp/.$RESOURCE_NAME.probe probefail=0 retries=0 |
設定探測的休息間隔
使用 hatimerun 啟動 nslookup ,傳送 Probe_timeout 值與識別目標主機
基於 nslookup 回覆碼的成功或失敗,設定 probefail 變數
如果 probefail 設定為 1 (失敗),將會確認對 nslookup 的回覆來自資料服務範例而非其他 DNS 伺服器
以下是 while 迴圈碼。
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
|