Sun Cluster 数据服务开发者指南(适用于 Solaris OS)

svc_start() 返回

即使 svc_start() 成功地返回,基础应用程序也可能无法启动。 因此,svc_start() 必须探测应用程序以验证在返回成功消息前运行了此应用程序。 该探测程序还必须将应用程序可能无法立即可用这一点考虑在内,因为该程序需要一些时间来启动。 svc_start() 方法将调用在 xfnts.c 中定义的 svc_wait() 来检验应用程序是否正在运行,如下所示。


/* 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 值的百分之三的超时值。 然后 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) 手册页。