Sun Cluster 資料服務開發者指南 (適用於 Solaris 作業系統)

探測程式如何工作

dns_probe 程式將實作一個連續執行的程序,來驗證由資料服務範例控制的 DNS 資源是否正在執行。dns_probedns_monitor_start 方法啟動,當資料服務範例置於離線後,該方法將由 RGM 自動執行。資料服務由 dns_monitor_stop 方法停止,在 RGM 將資料服務範例置於離線前,RGM 會執行該方法。

本節說明應用程式範例的 PROBE 方法之主要部分,不說明所有回呼方法的共用功能性,例如 parse_args() 函數。本小節也不說明如何使用 syslog() 函數。為所有方法提供共用功能性說明共用功能性。

如需 PROBE 方法的完整清單,請參閱PROBE 程式程式碼清單

探測程式有何作用

探測在無窮迴圈中執行。它使用 nslookup 驗證正確的 DNS 資源是否正在執行。如果 DNS 正在執行,探測方法將暫停規定的時間間隔 (由 Thorough_probe_interval 系統定義的特性設定) 並再次檢查。如果 DNS 未在執行,此程式將嘗試在本機重新啟動 DNS,或依據嘗試重新啟動的次數,要求 RGM 將資料服務重新置於其他節點。

獲取特性值

此程式需要以下特性的值︰

scha_resource_get() 函數獲取這些特性的值並將其儲存於 shell 變數中,如下所示︰

PROBE_INTERVAL=`scha_resource_get -O Thorough_probe_interval \
-R $RESOURCE_NAME -G $RESOURCEGROUP_NAME`

PROBE_TIMEOUT_INFO=`scha_resource_get -O Extension -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME Probe_timeout` 
Probe_timeout=`echo $probe_timeout_info | awk '{print $2}'`

DNS_HOST=`scha_resource_get -O Network_resources_used -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME`

RETRY_COUNT=`scha_resource_get -O Retry_count -R $RESOURCE_NAME -G \
$RESOURCEGROUP_NAME`

RETRY_INTERVAL=`scha_resource_get -O Retry_interval -R $RESOURCE_NAME -G \
$RESOURCEGROUP_NAME`

RT_BASEDIR=`scha_resource_get -O RT_basedir -R $RESOURCE_NAME -G \
 $RESOURCEGROUP_NAME`

備註 –

對於系統定義的特性 (如 Thorough_probe_intervalu),scha_resource_get() 函數會僅傳回值。對於延伸特性 (如 Probe_timeout),scha_resource_get() 函數會傳回類型和值。使用 awk 指令將僅獲取值。


檢查服務的可靠性

探測本身是 nslookup 指令的無窮 while 迴圈。在 while 迴圈之前,將會設置一個暫存檔以存放 nslookup 回覆。變數 probefailretries 初始化為 0。

# Set up a temporary file for the nslookup replies.
DNSPROBEFILE=/tmp/.$RESOURCE_NAME.probe
probefail=0
retries=0

while 迴圈執行以下作業︰

以下是 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

比較重新啟動與容錯移轉

如果 probefail 變數非 0 (成功),nslookup 指令逾時或回覆來自於伺服器而非服務範例的 DNS。在其中任何一種情況下,DNS 伺服器都不會發揮預期的功能,而故障監視器會呼叫 decide_restart_or_failover() 函數,以決定是在本機重新啟動資料服務還是要求 RGM 將資料服務重新置於其他節點。如果 probefail 變數為 0,將產生探測成功的訊息。

   if [ $probefail -ne 0 ]; then
         decide_restart_or_failover
   else
         logger -p ${SYSLOG_FACILITY}.err\
         -t [$SYSLOG_TAG]\
         "${ARGV0} Probe for resource HA-DNS successful"
   fi

decide_restart_or_failover() 函數使用時間間隔 (Retry_interval) 和失敗計數 (Retry_count) 來決定是否在本機上重新啟動 DNS,或要求 RGM 將資料服務遷移至其他節點。此函數將實作以下條件式邏輯。PROBE 程式程式碼清單中的 decide_restart_or_failover() 程式碼清單含有此程式碼。

如果重新啟動的次數達到了時間間隔內的限制次數,函數將要求 RGM 將資料服務重新置於其他節點。如果重新啟動的次數在限制範圍之內,或已超出間隔從而計數器重新開始計數,函數將嘗試重新啟動相同節點上的 DNS。請注意以下有關此函數的資訊:

重新啟動資料服務

restart_service() 函數由 decide_restart_or_failover() 呼叫,用來嘗試在同一節點上重新啟動資料服務。此函數執行以下邏輯︰

function restart_service
{

        # To restart the data service, first verify that the 
        # data service itself is still registered under PMF.
        pmfadm -q $PMF_TAG
        if [[ $? -eq 0 ]]; then
                # Since the TAG for the data service is still registered under
                # PMF, first stop the data service and start it back up again.

                # Obtain the Stop method name and the STOP_TIMEOUT value for
                # this resource.
                STOP_TIMEOUT=`scha_resource_get -O STOP_TIMEOUT \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                STOP_METHOD=`scha_resource_get -O STOP \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                hatimerun -t $STOP_TIMEOUT $RT_BASEDIR/$STOP_METHOD \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
                        -T $RESOURCETYPE_NAME

                if [[ $? -ne 0 ]]; then
                        logger-p ${SYSLOG_FACILITY}.err -t [$SYSLOG_TAG] \
                                “${ARGV0} Stop method failed.”
                        return 1
                fi

                # Obtain the START method name and the START_TIMEOUT value for
                # this resource.
                START_TIMEOUT=`scha_resource_get -O START_TIMEOUT \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                START_METHOD=`scha_resource_get -O START \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                hatimerun -t $START_TIMEOUT $RT_BASEDIR/$START_METHOD \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
                        -T $RESOURCETYPE_NAME

                if [[ $? -ne 0 ]]; then
                        logger-p ${SYSLOG_FACILITY}.err -t [$SYSLOG_TAG] \
                                “${ARGV0} Start method failed.”
                        return 1
                fi


        else
                # The absence of the TAG for the dataservice 
                # implies that the data service has already
                # exceeded the maximum retries allowed under PMF.
                # Therefore, do not attempt to restart the
                # data service again, but try to failover
                # to another node in the cluster.
                scha_control -O GIVEOVER -G $RESOURCEGROUP_NAME \
                        -R $RESOURCE_NAME
        fi

        return 0
}

探測退出狀態

如果資料服務範例的 PROBE 程式嘗試在本機上重新啟動失敗,並且嘗試容錯移轉至其他節點也失敗,則它將以失敗狀態結束。該程式記錄訊息 Failover attempt failed