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

Start 方法如何工作

當叢集節點上包含資料服務資源的資源群組置於線上或當資源群組已處於線上狀態並已啟用資源時,RGM 將執行該節點上的 Start 方法。在應用程式範例中,Start 方法將啟動該節點上的 in.named DNS 常駐程式。

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

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

Start 方法有何作用

在嘗試啟動 DNS 前,資料服務範例中的 Start 方法會驗證配置目錄和配置檔案 (named.conf) 是否可存取並可用。named.conf 中的資訊對於 DNS 成功作業是必要的。

此回呼方法使用 PMF (pmfadm) 啟動 DNS 常駐程式 (in.named)。如果 DNS 當機或無法啟動,PMF 將在指定的間隔內和規定的次數內嘗試啟動 DNS 常駐程式。重試的次數與間隔時間透過資料服務的 RTR 檔案中的特性來指定。

驗證配置

為了作業,DNS 需要配置目錄內 named.conf 檔案的資訊。因此,在嘗試啟動 DNS 之前,Start 方法將執行某些正常性檢查,以驗證目錄和檔案是否可存取。

Confdir 延伸特性提供配置目錄的路徑。特性本身定義在 RTR 檔案中。但是,當叢集管理員配置資料服務時,會指定其實際位置。

在資料服務範例中,Start 方法透過使用 scha_resource_get() 函數擷取配置目錄的位置。


備註 –

由於 Confdir 是一個延伸特性,因此 scha_resource_get() 將傳回類型與值。awk 指令會擷取此值並將其放入 shell 變數 CONFIG_DIR 中。


# find the value of Confdir set by the cluster administrator at the time of
# adding the resource.
config_info=`scha_resource_get -O Extension -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME Confdir`

# scha_resource_get returns the "type" as well as the "value" for the
# extension properties. Get only the value of the extension property 
CONFIG_DIR=`echo $config_info | awk '{print $2}'`

Start 方法使用 CONFIG_DIR 的值來驗證目錄是否可存取。如果不可存取,Start 會記錄錯誤訊息並以錯誤狀態結束。請參閱Start 退出狀態

# Check if $CONFIG_DIR is accessible.
if [ ! -d $CONFIG_DIR ]; then
   logger -p ${SYSLOG_FACILITY}.err \
         -t [$SYSLOG_TAG] \
         "${ARGV0} Directory $CONFIG_DIR is missing or not mounted"
   exit 1
fi

在啟動應用程式常駐程式之前,該方法將執行最後的檢查,以驗證 named.conf 檔案是否存在。如果檔案不存在,Start 會記錄一條錯誤訊息並以錯誤狀態結束。

# Change to the $CONFIG_DIR directory in case there are relative
# pathnames in the data files.
cd $CONFIG_DIR

# Check that the named.conf file is present in the $CONFIG_DIR directory
if [ ! -s named.conf ]; then
   logger -p ${SYSLOG_FACILITY}.err \
         -t [$SYSLOG_TAG] \
         "${ARGV0} File $CONFIG_DIR/named.conf is missing or empty"
   exit 1
fi

啟動應用程式

此方法使用程序管理員功能 (pmfadm) 啟動應用程式。pmfadm 指令可讓您設定在指定的時間框架內可以嘗試重新啟動應用程式的次數。RTR 檔案含有兩個特性︰Retry_count 指定嘗試重新啟動某一應用程式的次數,而 Retry_interval 則指定嘗試重新啟動某一應用程式的時間期間。

Start 方法透過使用 scha_resource_get () 函數擷取 Retry_count Retry_interval 的值並將這些值儲存於 shell 變數中。Start 方法透過使用 -n-t 選項將這些值傳送至 pmfadm

# Get the value for retry count from the RTR file.
RETRY_CNT=`scha_resource_get -O Retry_count -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME`
# Get the value for retry interval from the RTR file. This value is in seconds
# and must be converted to minutes for passing to pmfadm. Note that the 
# conversion rounds up; for example, 50 seconds rounds up to 1 minute.
((RETRY_INTRVAL=`scha_resource_get -O Retry_interval -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME` / 60))

# Start the in.named daemon under the control of PMF. Let it crash and restart
# up to $RETRY_COUNT times in a period of $RETRY_INTERVAL; if it crashes
# more often than that, PMF will cease trying to restart it.
# If there is a process already registered under the tag
# <$PMF_TAG>, then PMF sends out an alert message that the
# process is already running.
pmfadm -c $PMF_TAAG -n $RETRY_CNT -t $RETRY_INTRVAL \
    /usr/sbin/in.named -c named.conf

# Log a message indicating that HA-DNS has been started.
if [ $? -eq 0 ]; then
   logger -p ${SYSLOG_FACILITY}.err \
         -t [$SYSLOG_TAG] \
         "${ARGV0} HA-DNS successfully started"
fi
exit 0

Start 退出狀態

直到基本的應用程式確實執行並且可用時,特別是當其他資料服務附屬於該應用程式時,Start 方法才應以成功狀態結束。驗證是否成功的一個方法是在結束 Start 方法前,探測應用程式以確保其正在執行。對於複雜的應用程式 (如資料庫),請確定將 RTR 檔案中 Start_timeout 特性的值設定得足夠高,為應用程式初始化和從當機中回復留出時間。


備註 –

由於資料服務範例中的應用程式資源 (DNS) 啟動很快,資料服務範例將不會輪詢以驗證在以成功狀態結束前該資源是否正在執行。


如果該方法無法啟動 DNS 並以失敗狀態退出,RGM 將檢查 Failover_mode 特性 (其決定如何反應)。資料服務範例沒有明確設定 Failover_mode 特性,因此該特性具有預設值 NONE (除非叢集管理員置換預設值並指定不同的值)。在這種情況下,RGM 僅會設定資料服務的狀態,而不採取其他任何動作。叢集管理員需要對在同一節點上進行重新啟動或容錯移轉至其他節點。