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

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 Font Server 之前验证服务

xfnts_start 方法尝试启动 X Font Server 之前,它将调用 svc_validate() 来验证正确配置是否已就位以支持 xfs 守护进程。

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

有关详细信息,请参见“xfnts_validate 方法”。

使用 svc_start() 启动服务

xfnts_start 方法将调用在 xfnts.c 文件中定义的 svc_start() 方法来启动 xfs 守护进程。本节将介绍 svc_start ()

用于启动 xfs 守护进程的命令如下:


# xfs -config config-directory/fontserver.cfg -port port-number

Confdir_list 扩展属性用于标识 config-directoryPort_list 系统属性用于标识 port-number。当群集管理员配置数据服务时,将提供这些属性的具体值。

xfnts_start 方法将这些属性声明为字符串数组。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() 方法将调用在 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() 以获取探测应用程序所需的网络地址资源。

/* 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) 手册页包含更多信息。