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 檔案的資訊。因此,Start 方法將執行一些完整檢查,以驗證在嘗試啟動 DNS 之前目錄與檔案是否均可存取。

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_countRetry_interval 的值,並將它們的值儲存於 shell 變數中。然後使用 -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 僅會設定資料服務的狀態,而不採取其他任何動作。在相同的節點上重新啟動或故障轉移至其他節點,都需要使用者介入。