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

xfnts_start 方法

當包含資料服務資源的資源群組在叢集節點上處於線上運作狀態或當啟用該資源時,RGM 將在該節點上呼叫 Start 方法。 在 SUNW.xfnts 範例資源類型中,xfnts_start 方法可在該節點上啟動 xfs 常駐程式。

xfnts_start 方法呼叫 scds_pmf_start(),以在 PMF 下啟動此常駐程式。 PMF 提供了自動故障通知與重新啟動功能,以及與故障監視器的整合。


註解 –

xfnts_start 中的第一次呼叫是呼叫 scds_initialize(),它執行某些必需的事務性工作功能 (scds_initialize() 函式scds_initialize(3HA) 線上說明手冊包含更多詳細資訊)。


啟動前驗證服務

在嘗試啟動 X 字型伺服器之前,xfnts_start 方法將呼叫 svc_validate(),以確認正確的配置已就緒來支援 xfs 常駐程式 (請參閱xfnts_validate 方法以取得詳細資訊),如下所示。


rc = svc_validate(scds_handle);
   if (rc != 0) {
      scds_syslog(LOG_ERR,
          "Failed to validate configuration.");
      return (rc);
   }

啟動服務

xfnts_start 方法呼叫在 xfnts.c 中定義的 svc_start() 方法來啟動 xfs 常駐程式。 本節說明了 svc_start ()

用來啟動 xfs 常駐程式的指令如下所述。


xfs -config config_directory/fontserver.cfg -port port_number

Confdir_list 延伸屬性識別 config_directory,而 Port_list 系統屬性識別 port_number。 當叢集管理員配置資料服務時,他會為這些屬性提供特定值。

xfnts_start 方法將這些屬性宣告為字串陣列,並使用 scds_get_ext_confdir_list()scds_get_port_list() 函式 (在 scds_property_functions(3HA) 中有說明) 取得管理員設定的值,如下所示。


scha_str_array_t *confdirs;
scds_port_list_t    *portlist;
scha_err_t   err;

   /* get the configuration directory from the confdir_list property */
   confdirs = scds_get_ext_confdir_list(scds_handle);

   (void) sprintf(xfnts_conf, "%s/fontserver.cfg", confdirs->str_array[0]);

   /* obtain the port to be used by XFS from the Port_list property */
   err = scds_get_port_list(scds_handle, &portlist);
   if (err != SCHA_ERR_NOERR) {
      scds_syslog(LOG_ERR,
          "Could not access property Port_list.");
      return (1);
   }

請注意,confdirs 變數指陣列的第一個元素 (0)。

xfnts_start 方法使用 sprintf 來產生 xfs 的指令行,如下所示。


/* Construct the command to start the xfs daemon. */
   (void) sprintf(cmd,
       "/usr/openwin/bin/xfs -config %s -port %d 2>/dev/null",
       xfnts_conf, portlist->ports[0].port);

請注意,他的輸出將重新導向至 dev/null,來抑制此常駐程式產生的訊息。

xfnts_start 方法將 xfs 指令行傳送至 scds_pmf_start(),以啟動 PMF 控制下的資料服務,如下所示。


scds_syslog(LOG_INFO, "Issuing a start request.");
   err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_SVC,
      SCDS_PMF_SINGLE_INSTANCE, cmd, -1);

   if (err == SCHA_ERR_NOERR) {
      scds_syslog(LOG_INFO,
          "Start command completed successfully.");
   } else {
      scds_syslog(LOG_ERR,
          "Failed to start HA-XFS ");
   }

請注意關於 scds_pmf_start() 呼叫的以下內容。

在傳回前,svc_pmf_start() 將釋放為 portlist 結構分配的記憶體空間,如下所示。


scds_free_port_list(portlist);
return (err);

svc_start() 傳回

即使 svc_start() 成功傳回,基礎應用程式也可能無法啟動。 因此,svc_start() 必須探測應用程式,以驗證該應用程式在傳回成功訊息之前已在執行。 此探測也必須考慮此應用程式可能不會立即可用,因為它要花些時間來啟動。 svc_start() 方法將呼叫 svc_wait() (在 xfnts.c 中定義),以確認此應用程式正在執行,如下所示。


/* Wait for the service to start up fully */
   scds_syslog_debug(DBG_LEVEL_HIGH,
       "Calling svc_wait to verify that service has started.");

   rc = svc_wait(scds_handle);

   scds_syslog_debug(DBG_LEVEL_HIGH,
       "Returned from svc_wait");

   if (rc == 0) {
      scds_syslog(LOG_INFO, "Successfully started the service.");
   } else {
      scds_syslog(LOG_ERR, "Failed to start the service.");
   }

svc_wait() 函式呼叫 scds_get_netaddr_list(3HA),來取得探測此應用程式所需的網路位址資源,如下所示。


/* obtain the network resource to use for probing */
   if (scds_get_netaddr_list(scds_handle, &netaddr)) {
      scds_syslog(LOG_ERR,
          "No network address resources found in resource group.");
      return (1);
   }

   /* Return an error if there are no network resources */
   if (netaddr == NULL || netaddr->num_netaddrs == 0) {
      scds_syslog(LOG_ERR,
          "No network address resource in resource group.");
      return (1);
   }

然後,svc_wait() 便可取得 start_timeoutstop_timeout 值,如下所示。


svc_start_timeout = scds_get_rs_start_timeout(scds_handle)
   probe_timeout = scds_get_ext_probe_timeout(scds_handle)

若要說明伺服器可能需要的啟動時間,svc_wait() 將呼叫 scds_svc_wait(),並傳送相當於 start_timeout 值 3% 的逾時值。 然後,svc_wait() 將呼叫 svc_probe(),以確認此應用程式已經啟動。 svc_probe() 方法在指定通訊埠上建立與伺服器的簡單套接字連接。 如果無法連接至該通訊埠,svc_probe() 將傳回值 100,指示發生完全故障。 如果連接成功,但與該通訊埠斷開連接失敗,則 svc_probe() 將傳回值 50。

svc_probe() 失敗或部分失敗時,svc_wait() 將以逾時值 5 呼叫 scds_svc_wait()scds_svc_wait() 方法會將探測頻率限定為每五秒一次。 此方法也將計算嘗試啟動服務的次數。 如果嘗試次數在資源的 Retry_interval 屬性所指定的時間內,超出該資源 Retry_count 屬性的值,則 scds_svc_wait() 函式將傳回故障。 在此情況下,svc_start() 函式也將傳回故障。


#define    SVC_CONNECT_TIMEOUT_PCT    95
#define    SVC_WAIT_PCT       3
   if (scds_svc_wait(scds_handle, (svc_start_timeout * SVC_WAIT_PCT)/100)
      != SCHA_ERR_NOERR) {

      scds_syslog(LOG_ERR, "Service failed to start.");
      return (1);
   }

   do {
      /*
       * probe the data service on the IP address of the
       * network resource and the portname
       */
      rc = svc_probe(scds_handle,
          netaddr->netaddrs[0].hostname,
          netaddr->netaddrs[0].port_proto.port, probe_timeout);
      if (rc == SCHA_ERR_NOERR) {
         /* Success. Free up resources and return */
         scds_free_netaddr_list(netaddr);
         return (0);
      }

       /* Call scds_svc_wait() so that if service fails too
      if (scds_svc_wait(scds_handle, SVC_WAIT_TIME)
         != SCHA_ERR_NOERR) {
         scds_syslog(LOG_ERR, "Service failed to start.");
         return (1);
      }

   /* Rely on RGM to timeout and terminate the program */
   } while (1);


註解 –

在結束之前,xfnts_start 方法將呼叫 scds_close() 以回收 scds_initialize() 分配的資源。 請參閱scds_initialize() 函式scds_close(3HA) 線上援助頁,以取得詳細資訊。