本章介绍了使用数据服务开发库 (DSDL) 实现的资源类型样例 SUNW.xfnts。此数据服务是使用 C 语言编写的。底层应用程序为 X Font Server,它是基于 TCP/IP 的服务。附录 C,DSDL 样例资源类型代码列表 包含 SUNW.xfnts 资源类型中每个方法的完整代码。
本章包括以下主题:
X Font Server 是基于 TCP/IP 的服务,该服务向其客户机提供字体文件。客户机将连接该服务器,请求提供字体集,该服务器将从磁盘读取相应的字体文件并将它们提供给客户机。X Font Server 守护进程包含位于 /usr/openwin/bin/xfs 的服务器二进制文件。该守护进程通常通过 inetd 启动。但是,对于当前的样例,假定 /etc/inetd.conf 文件中的正确条目已被禁用(例如,通过使用 fsadmin -d 命令),以使守护进程处于 Sun Cluster 软件的单独控制下。
默认情况下,X Font Server 从 /usr/openwin/lib/X11/fontserver.cfg 文件中读取其配置信息。此文件中的目录条目包含可用于守护进程提供服务的字体目录列表。群集管理员可以在群集文件系统中找到字体目录。通过在系统的字体数据库中维护一个单独的副本,此位置优化了 X Font Server 在 Sun Cluster 上的使用。如果群集管理员需要更改此位置,则必须编辑 fontserver.cfg 以反映新的字体目录路径。
为了简化配置,群集管理员还可以将配置文件本身置于群集文件系统中。xfs 守护进程提供了覆盖该文件默认的内置位置的命令行参数。SUNW.xfnts 资源类型使用以下命令启动在 Sun Cluster 软件控制下的守护进程。
/usr/openwin/bin/xfs -config location-of-configuration-file/fontserver.cfg \ -port port-number
在 SUNW.xfnts 资源类型实现中,可以使用 Confdir_list 属性来管理 fontserver.cfg 配置文件的位置。
xfs 服务器守护进程侦听的 TCP 端口号通常为 “fs” 端口,该端口在 /etc/services 文件中通常定义为 7100。但是,群集管理器附带的 xfs 命令的 -port 选项使群集管理器可以覆盖默认设置。
可以使用 SUNW.xfnts 资源类型中的 Port_list 属性设置默认值并使群集管理器可以将 -port 选项与 xfs 命令结合使用。在 RTR 文件中您需要将此属性的缺省值定义为 7100/tcp。在 SUNW.xfnts Start 方法中,可以将 Port_list 传递给 xfs 命令行上的 -port 选项。因此,此资源类型的用户无需指定端口号(默认端口为 7100/tcp)。群集管理员在配置资源类型时,可以指定其他 Port_list 属性值。
本节介绍了 SUNW.xfnts RTR 文件中的几个主要属性。本节并未介绍该文件中每个属性的作用,对于此类说明,请参见“设置资源和资源类型属性”。
Confdir_list 扩展属性用于标识配置目录(或目录列表),如下所示:
{
PROPERTY = Confdir_list;
EXTENSION;
STRINGARRAY;
TUNABLE = AT_CREATION;
DESCRIPTION = "The Configuration Directory Path(s)";
}
Confdir_list 属性未指定缺省值。创建资源时,群集管理员必须指定目录名称。该值以后不能更改,因为可调性被限制为 AT_CREATION。
Port_list 属性用于标识服务器守护进程进行侦听的端口,如下所示:
{
PROPERTY = Port_list;
DEFAULT = 7100/tcp;
TUNABLE = ANYTIME;
}
由于属性将声明默认值,因此,群集管理员可以在创建资源时指定新值或接受默认值。任何人以后都不能更改该值,因为可调性被限制为 AT_CREATION。
RMAPI 函数以 scha_ 开头。
DSDL 函数以 scds_ 开头。
回调方法以 xfnts_ 开头。
用户编写的函数以 svc_ 开头。
DSDL 要求每个回调方法在方法的开头都要调用 scds_initialize() 函数。此函数可执行以下操作:
检查和处理框架传递给数据服务方法的命令行参数(argc 和 argv)。方法无需处理任何附加命令行参数。
设置内部数据结构,以供 DSDL 中的其他函数使用。
初始化记录环境。
验证故障监视器探测程序设置。
使用 scds_close() 函数可以收回由 scds_initialize() 分配的资源。
当包含数据服务资源的资源组在群集节点上联机或启用资源时,RGM 将在该群集节点上运行 Start 方法。在资源类型样例 SUNW.xfnts 中,xfnts_start 方法将激活该节点上的 xfs 守护进程。
xfnts_start 方法将调用 scds_pmf_start() 以启动 PMF 下的守护进程。PMF 提供了自动失败通知和重新启动功能,并集成了故障监视器。
xfnts_start 将首先调用执行一些必要的内务处理函数的 scds_initialize()。scds_initialize() 函数和 scds_initialize(3HA) 手册页包含更多信息。
在 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 方法”。
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 方法将这些属性声明为字符串数组。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() 以获取探测应用程序所需的网络地址资源。
/* 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) 手册页包含更多信息。
由于 xfnts_start 方法使用 scds_pmf_start() 启动 PMF 下的服务,因此,xfnts_stop 将使用 scds_pmf_stop() 来停止该服务。
xfnts_stop 将首先调用执行一些必要的内务处理函数的 scds_initialize()。scds_initialize() 函数和 scds_initialize(3HA) 手册页包含更多信息。
xfnts_stop 方法将调用在 xfnts.c 文件中定义的 svc_stop() 方法,如下所示:
scds_syslog(LOG_ERR, "Issuing a stop request.");
err = scds_pmf_stop(scds_handle,
SCDS_PMF_TYPE_SVC, SCDS_PMF_SINGLE_INSTANCE, SIGTERM,
scds_get_rs_stop_timeout(scds_handle));
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to stop HA-XFS.");
return (1);
}
scds_syslog(LOG_INFO,
"Successfully stopped HA-XFS.");
return (SCHA_ERR_NOERR); /* Successfully stopped */
关于在 svc_stop() 中对 scds_pmf_stop() 函数的调用,请注意以下几点:
SCDS_PMF_TYPE_SVC 参数将程序标识为作为数据服务应用程序停止。此方法还可以停止故障监视器或某个其他类型的应用程序。
SCDS_PMF_SINGLE_INSTANCE 参数用于标识信号。
SIGTERM 参数将标识用于停止资源实例的信号。如果此信号无法停止该实例,scds_pmf_stop() 将发送 SIGKILL 来停止该实例,如果仍然失败,则会返回超时错误。有关详细信息,请参见 scds_pmf_stop(3HA) 手册页。
超时值即该资源的 Stop_timeout 属性的值。
退出前,xfnts_stop 方法将调用 scds_close() 来收回由 scds_initialize() 分配的资源。scds_initialize() 函数和 scds_close(3HA) 手册页包含更多信息。
在节点上启动资源后,RGM 将在该节点上调用 Monitor_start 方法以启动故障监视器。xfnts_monitor_start 方法将使用 scds_pmf_start() 来启动 PMF 下的监视器守护进程。
xfnts_monitor_start 将首先调用执行一些必要的内务处理函数的 scds_initialize()。scds_initialize() 函数和 scds_initialize(3HA) 手册页包含更多信息。
xfnts_monitor_start 方法用于调用在 xfnts.c 文件中定义的 mon_start 方法,如下所示:
scds_syslog_debug(DBG_LEVEL_HIGH,
"Calling Monitor_start method for resource <%s>.",
scds_get_resource_name(scds_handle));
/* Call scds_pmf_start and pass the name of the probe. */
err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_MON,
SCDS_PMF_SINGLE_INSTANCE, "xfnts_probe", 0);
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to start fault monitor.");
return (1);
}
scds_syslog(LOG_INFO,
"Started the fault monitor.");
return (SCHA_ERR_NOERR); /* Successfully started Monitor */
}
关于在 svc_mon_start() 中对 scds_pmf_start() 函数的调用,请注意以下几点:
SCDS_PMF_TYPE_MON 参数标识程序作为故障监视器启动。此方法还可以启动数据服务或某个其他类型的应用程序。
SCDS_PMF_SINGLE_INSTANCE 参数将此标识为单实例资源。
xfnts_probe 参数用于标识要启动的监视器守护进程。假定监视器守护进程与其他回调程序位于同一目录下。
最后一个参数 0 用于指定子监视级别。在这种情况下,此值将指定 PMF 仅监视监视器守护进程。
退出前,xfnts_monitor_start 方法将调用 scds_close() 以收回由 scds_initialize() 分配的资源。scds_initialize() 函数和 scds_close(3HA) 手册页包含更多信息。
由于 xfnts_monitor_start 方法使用 scds_pmf_start() 来启动 PMF 下的监视器守护进程,xfnts_monitor_stop 将使用 scds_pmf_stop() 来停止监视器守护进程。
xfnts_monitor_stop 将首先调用执行一些必要的内务处理函数的 scds_initialize()。scds_initialize() 函数和 scds_initialize(3HA) 手册页包含更多信息。
xfnts_monitor_stop 方法用于调用在 xfnts.c 文件中定义的 mon_stop() 方法,如下所示:
scds_syslog_debug(DBG_LEVEL_HIGH,
"Calling scds_pmf_stop method");
err = scds_pmf_stop(scds_handle, SCDS_PMF_TYPE_MON,
SCDS_PMF_SINGLE_INSTANCE, SIGKILL,
scds_get_rs_monitor_stop_timeout(scds_handle));
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to stop fault monitor.");
return (1);
}
scds_syslog(LOG_INFO,
"Stopped the fault monitor.");
return (SCHA_ERR_NOERR); /* Successfully stopped monitor */
}
关于在 svc_mon_stop() 中对 scds_pmf_stop() 函数的调用,请注意以下几点:
SCDS_PMF_TYPE_MON 参数用于标识程序应作为故障监视器停止。此方法还可以停止数据服务或某个其他类型的应用程序。
SCDS_PMF_SINGLE_INSTANCE 参数将此标识为单实例资源。
SIGKILL 参数将标识用于停止资源实例的信号。如果此信号无法停止该实例,则 scds_pmf_stop() 将会返回超时错误。有关详细信息,请参见 scds_pmf_stop(3HA) 手册页。
超时值是资源的 Monitor_stop_timeout 属性的值。
退出前,xfnts_monitor_stop 方法将调用 scds_close() 以收回由 scds_initialize() 分配的资源。scds_initialize() 函数和 scds_close(3HA) 手册页包含更多信息。
只要故障监视器尝试将包含该资源的资源组故障转移到其他节点,RGM 就将调用 Monitor_check 方法。xfnts_monitor_check 方法将调用 svc_validate() 方法以验证正确配置是否已就位以支持 xfs 守护进程。有关详细信息,请参见“xfnts_validate 方法”。xfnts_monitor_check 的代码如下:
/* Process the arguments passed by RGM and initialize syslog */
if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR)
{
scds_syslog(LOG_ERR, "Failed to initialize the handle.");
return (1);
}
rc = svc_validate(scds_handle);
scds_syslog_debug(DBG_LEVEL_HIGH,
"monitor_check method "
"was called and returned <%d>.", rc);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of validate method run as part of monitor check */
return (rc);
}
在节点上启动资源后,RGM 不直接调用 PROBE 方法,而是调用 Monitor_start 方法来启动监视器。xfnts_monitor_start 方法用于启动在 PMF 控制下的故障监视器。xfnts_monitor_stop 方法用于停止故障监视器。
SUNW.xfnts 故障监视器可以执行以下操作:
通过使用为检查基于 TCP 的简单服务专门设计的实用程序(例如 xfs),定期监视 xfs 服务器守护进程的运行状况。
跟踪应用程序在时间窗口内遇到的问题(使用 Retry_count 和 Retry_interval 属性),并在应用程序完全失败时决定是重新启动还是故障转移数据服务。scds_fm_action() 和 scds_fm_sleep() 函数为此跟踪和决定机制提供了内置支持。
使用 scds_fm_action() 实现故障转移或重新启动决策。
更新资源状态,并使资源状态可用于管理工具和 GUI。
xfonts_probe 方法用于实现循环。实现循环前,xfonts_probe 将执行以下操作:
检索 xfnts 资源的网络地址资源,如下所示:
/* Get the ip addresses available for this resource */
if (scds_get_netaddr_list(scds_handle, &netaddr)) {
scds_syslog(LOG_ERR,
"No network address resource in resource group.");
scds_close(&scds_handle);
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);
}
调用 scds_fm_sleep() 并将 Thorough_probe_interval 的值作为超时值传递。探测将根据探测之间的 Thorough_probe_interval 值进行休眠,如下所示:
timeout = scds_get_ext_probe_timeout(scds_handle);
for (;;) {
/*
* sleep for a duration of thorough_probe_interval between
* successive probes.
*/
(void) scds_fm_sleep(scds_handle,
scds_get_rs_thorough_probe_interval(scds_handle));
xfnts_probe 方法用于实现以下循环:
for (ip = 0; ip < netaddr->num_netaddrs; ip++) {
/*
* Grab the hostname and port on which the
* health has to be monitored.
*/
hostname = netaddr->netaddrs[ip].hostname;
port = netaddr->netaddrs[ip].port_proto.port;
/*
* HA-XFS supports only one port and
* hence obtain the port value from the
* first entry in the array of ports.
*/
ht1 = gethrtime(); /* Latch probe start time */
scds_syslog(LOG_INFO, "Probing the service on port: %d.", port);
probe_result =
svc_probe(scds_handle, hostname, port, timeout);
/*
* Update service probe history,
* take action if necessary.
* Latch probe end time.
*/
ht2 = gethrtime();
/* Convert to milliseconds */
dt = (ulong_t)((ht2 - ht1) / 1e6);
/*
* Compute failure history and take
* action if needed
*/
(void) scds_fm_action(scds_handle,
probe_result, (long)dt);
} /* Each net resource */
} /* Keep probing forever */
svc_probe() 函数将实现探测程序逻辑。svc_probe() 的返回值被传递给 scds_fm_action(),后者用于确定是重新启动应用程序,是将资源组故障转移,还是不进行任何操作。
svc_probe() 函数通过调用 scds_fm_tcp_connect() 建立与指定端口的简单套接字连接。如果连接失败,svc_probe() 将返回一个值 100,该值表示完全失败。如果连接成功,但是断开连接失败,svc_probe() 将返回一个值 50,该值表示部分失败。如果连接和断开连接都成功,svc_probe() 将返回一个值 0,该值表示成功。
svc_probe() 的代码如下:
int svc_probe(scds_handle_t scds_handle,
char *hostname, int port, int timeout)
{
int rc;
hrtime_t t1, t2;
int sock;
char testcmd[2048];
int time_used, time_remaining;
time_t connect_timeout;
/*
* probe the data service by doing a socket connection to the port
* specified in the port_list property to the host that is
* serving the XFS data service. If the XFS service which is configured
* to listen on the specified port, replies to the connection, then
* the probe is successful. Else we will wait for a time period set
* in probe_timeout property before concluding that the probe failed.
*/
/*
* Use the SVC_CONNECT_TIMEOUT_PCT percentage of timeout
* to connect to the port
*/
connect_timeout = (SVC_CONNECT_TIMEOUT_PCT * timeout)/100;
t1 = (hrtime_t)(gethrtime()/1E9);
/*
* the probe makes a connection to the specified hostname and port.
* The connection is timed for 95% of the actual probe_timeout.
*/
rc = scds_fm_tcp_connect(scds_handle, &sock, hostname, port,
connect_timeout);
if (rc) {
scds_syslog(LOG_ERR,
"Failed to connect to port <%d> of resource <%s>.",
port, scds_get_resource_name(scds_handle));
/* this is a complete failure */
return (SCDS_PROBE_COMPLETE_FAILURE);
}
t2 = (hrtime_t)(gethrtime()/1E9);
/*
* Compute the actual time it took to connect. This should be less than
* or equal to connect_timeout, the time allocated to connect.
* If the connect uses all the time that is allocated for it,
* then the remaining value from the probe_timeout that is passed to
* this function will be used as disconnect timeout. Otherwise, the
* the remaining time from the connect call will also be added to
* the disconnect timeout.
*
*/
time_used = (int)(t2 - t1);
/*
* Use the remaining time(timeout - time_took_to_connect) to disconnect
*/
time_remaining = timeout - (int)time_used;
/*
* If all the time is used up, use a small hardcoded timeout
* to still try to disconnect. This will avoid the fd leak.
*/
if (time_remaining <= 0) {
scds_syslog_debug(DBG_LEVEL_LOW,
"svc_probe used entire timeout of "
"%d seconds during connect operation and exceeded the "
"timeout by %d seconds. Attempting disconnect with timeout"
" %d ",
connect_timeout,
abs(time_used),
SVC_DISCONNECT_TIMEOUT_SECONDS);
time_remaining = SVC_DISCONNECT_TIMEOUT_SECONDS;
}
/*
* Return partial failure in case of disconnection failure.
* Reason: The connect call is successful, which means
* the application is alive. A disconnection failure
* could happen due to a hung application or heavy load.
* If it is the later case, don't declare the application
* as dead by returning complete failure. Instead, declare
* it as partial failure. If this situation persists, the
* disconnect call will fail again and the application will be
* restarted.
*/
rc = scds_fm_tcp_disconnect(scds_handle, sock, time_remaining);
if (rc != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to disconnect to port %d of resource %s.",
port, scds_get_resource_name(scds_handle));
/* this is a partial failure */
return (SCDS_PROBE_COMPLETE_FAILURE/2);
}
t2 = (hrtime_t)(gethrtime()/1E9);
time_used = (int)(t2 - t1);
time_remaining = timeout - time_used;
/*
* If there is no time left, don't do the full test with
* fsinfo. Return SCDS_PROBE_COMPLETE_FAILURE/2
* instead. This will make sure that if this timeout
* persists, server will be restarted.
*/
if (time_remaining <= 0) {
scds_syslog(LOG_ERR, "Probe timed out.");
return (SCDS_PROBE_COMPLETE_FAILURE/2);
}
/*
* The connection and disconnection to port is successful,
* Run the fsinfo command to perform a full check of
* server health.
* Redirect stdout, otherwise the output from fsinfo
* ends up on the console.
*/
(void) sprintf(testcmd,
"/usr/openwin/bin/fsinfo -server %s:%d > /dev/null",
hostname, port);
scds_syslog_debug(DBG_LEVEL_HIGH,
"Checking the server status with %s.", testcmd);
if (scds_timerun(scds_handle, testcmd, time_remaining,
SIGKILL, &rc) != SCHA_ERR_NOERR || rc != 0) {
scds_syslog(LOG_ERR,
"Failed to check server status with command <%s>",
testcmd);
return (SCDS_PROBE_COMPLETE_FAILURE/2);
}
return (0);
}
完成时,svc_probe() 将返回一个值,来表示操作是成功 (0)、是部分失败 (50) 还是完全失败 (100)。xfnts_probe 方法将把此值传送到 scds_fm_action()。
xfnts_probe 方法将调用 scds_fm_action() 来确定要执行的操作。scds_fm_action() 的逻辑如下:
保留 Retry_interval 属性值内的累积失败历史记录。
如果累积失败次数达到 100 次(完全失败),则重新启动数据服务。如果超出 Retry_interval 的值,将重置该历史记录。
如果在 Retry_interval 指定的时间内,重新启动次数超出了 Retry_count 属性的值,则故障转移该数据服务。
例如,假定探测建立了与 xfs 服务器的连接,但断开连接时失败。这表明该服务器正在运行,但是可能处于挂起状态或恰好处于临时装入状态。断开连接失败将向 scds_fm_action() 发送部分失败 (50)。此值虽然小于用来重启该数据服务的阈值,但是它将保留在失败历史记录中。
如果在下次探测时断开服务器连接再次失败,值 50 将被添加到由 scds_fm_action() 维护的失败历史记录中。累积失败值现在为 100,因此 scds_fm_action() 将重新启动数据服务。
创建资源时,以及群集管理员更新资源的属性或其包含组时,RGM 将调用 Validate 方法。在进行创建或更新之前,RGM 将调用 Validate,任何节点上该方法返回失败出口代码都将导致创建或更新操作取消。
仅当群集管理员更改资源或资源组属性,或当监视器设置 Status 和 Status_msg 资源属性时,RGM 才会调用 Validate。RGM 在设置属性时不调用 Validate。
只要 PROBE 方法尝试将数据服务故障转移到新节点上,Monitor_check 方法还将显式调用 Validate 方法。
RGM 将对传递给其他方法的那些正被更新的属性和值调用 Validate 和其他参数。在 xfnts_validate 的开头调用 scds_initialize() 将解析 RGM 传递给 xfnts_validate 所有参数和存储在 scds_handle 参数中的信息。xfnts_validate 调用的子例行程序将使用此信息。
xfnts_validate 方法将调用 svc_validate() 以验证以下条件:
已经为该资源设置了 Confdir_list 属性并定义了一个目录。
scha_str_array_t *confdirs;
confdirs = scds_get_ext_confdir_list(scds_handle);
/* Return error if there is no confdir_list extension property */
if (confdirs == NULL || confdirs->array_cnt != 1) {
scds_syslog(LOG_ERR,
"Property Confdir_list is not set properly.");
return (1); /* Validation failure */
}
Confdir_list 所指定的目录包含 fontserver.cfg 文件。
(void) sprintf(xfnts_conf, "%s/fontserver.cfg", confdirs->str_array[0]);
if (stat(xfnts_conf, &statbuf) != 0) {
/*
* suppress lint error because errno.h prototype
* is missing void arg
*/
scds_syslog(LOG_ERR,
"Failed to access file <%s> : <%s>",
xfnts_conf, strerror(errno)); /*lint !e746 */
return (1);
}
该服务器守护进程二进制文件可以在该群集节点上访问。
if (stat("/usr/openwin/bin/xfs", &statbuf) != 0) {
scds_syslog(LOG_ERR,
"Cannot access XFS binary : <%s> ", strerror(errno));
return (1);
}
Port_list 属性将指定单个端口。
scds_port_list_t *portlist;
err = scds_get_port_list(scds_handle, &portlist);
if (err != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Could not access property Port_list: %s.",
scds_error_string(err));
return (1); /* Validation Failure */
}
#ifdef TEST
if (portlist->num_ports != 1) {
scds_syslog(LOG_ERR,
"Property Port_list must have only one value.");
scds_free_port_list(portlist);
return (1); /* Validation Failure */
}
#endif
包含数据服务的资源组还至少包含一个网络地址资源。
scds_net_resource_list_t *snrlp;
if ((err = scds_get_rs_hostnames(scds_handle, &snrlp))
!= SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"No network address resource in resource group: %s.",
scds_error_string(err));
return (1); /* Validation Failure */
}
/* Return an error if there are no network address resources */
if (snrlp == NULL || snrlp->num_netresources == 0) {
scds_syslog(LOG_ERR,
"No network address resource in resource group.");
rc = 1;
goto finished;
}
在返回之前,svc_validate() 将释放所有分配的资源。
finished: scds_free_net_list(snrlp); scds_free_port_list(portlist); return (rc); /* return result of validation */
退出前,xfnts_validate 方法将调用 scds_close() 以收回由 scds_initialize() 分配的资源。scds_initialize() 函数和 scds_close(3HA) 手册页包含更多信息。
RGM 将调用 Update 方法以通知正在运行的资源其属性已更改。唯一可为 xfnts 数据服务更改的属性与故障监视器有关。因此,只要更新了属性,xfnts_update 方法就将调用 scds_pmf_restart_fm() 以重新启动故障监视器。
/* check if the Fault monitor is already running and if so stop
* and restart it. The second parameter to scds_pmf_restart_fm()
* uniquely identifies the instance of the fault monitor that needs
* to be restarted.
*/
scds_syslog(LOG_INFO, "Restarting the fault monitor.");
result = scds_pmf_restart_fm(scds_handle, 0);
if (result != SCHA_ERR_NOERR) {
scds_syslog(LOG_ERR,
"Failed to restart fault monitor.");
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
return (1);
}
scds_syslog(LOG_INFO,
"Completed successfully.");
如果故障监视器有多个实例,则 scds_pmf_restart_fm() 的第二个参数将唯一标识要被重新启动的故障监视器实例。示例中的值 0 用于指明故障监视器只有一个实例。