使含有数据服务资源的资源组在群集节点上联机时或启用该资源时,RGM 将对该节点调用 Start 方法。 在 SUNW.xfnts 资源类型样例中,xfnts_start 方法将激活该节点上的 xfs 守护程序。
xfnts_start 方法将在 PMF 控制下调用 scds_pmf_start() 启动该守护程序。 除了与故障监视器集成以外,PMF 还提供了自动的失败通知并重启的功能。
在 xfnts_start 中首先调用的是 scds_initialize(),该函数执行一些必要的内务处理功能(scds_initialize() 函数和 scds_initialize(3HA) 手册页中包含详细信息)。
在尝试启动 X Font Server 之前,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() 进行调用的内容。
SCDS_PMF_TYPE_SVC 参数用来标识要作为数据服务应用程序启动的程序 — 此方法也可以启动故障监视器或一些其它类型的应用程序。
SCDS_PMF_SINGLE_INSTANCE 参数用来将此资源标识为单实例资源。
cmd 参数是指先前生成的命令行。
最后一个参数 -1 用来指定子监视级别。 -1 指定 PMF 要监视所有子进程以及原始进程。
在返回之前,svc_pmf_start() 将释放为 portlist 结构分配的内存,如下所示。
scds_free_port_list(portlist); return (err); |
即使 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_timeout 和 stop_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) 手册页。