9 特殊考虑
9.1 Licensing
任何时候,我们都鼓励开发者使用GPL (GNU General Public License) 2.0 或者更新的版本。shell库函数不严格限制于此,它是基于LGPL( GNU Lesser General Public License)版本2.1 或更新版本的,这样non-GPL的资源的代理可以使用。
资源代理必须在源代码显式的标明其授权信息。
9.2 本地设定
当运行 .ocf-shellfuncs (4.3节 初始化 有说明),资源代理自动设定 LANG 和 LC_ALL到C的区域设置。资源代理可以期待总是在C的区域设置里操作,不需要重置LANG和LC_ 环境变量。
9.3 测试运行进程
测试一个指定的进程(知道进程id)是否正在运行,通常的做法是发送一个0信号并捕获错误。比如:
重要:一种远优于上述做法的例子是使用一个守护进程的客户端调用一个守护进程的功能,如5.3节 monitor action的例子。
9.4 设定master特性
有状态(master/slave)资源必须设定其自己的master特性,这些特性会为集群管理提供一些信息,帮助它确定谁是最合适提升为master角色的节点。
为此目标,crm_master 比较方便。它封装了crm_attribute 来设置其运行节点上的属性 master-$OCF_RESOURCE_INSTANCE为一个特定的值。集群管理器会将相应实例的这些改变转换为提升分数,其提升的特征基于此。
有状态的资源代理在monitor和notity行为时执行crm_master。
下面的例子假设foobar资源代理可以通过执行一个有返回值的执行文件测试应用的状态。这个返回值取决于是否:
资源代理必须在源代码显式的标明其授权信息。
9.2 本地设定
当运行 .ocf-shellfuncs (4.3节 初始化 有说明),资源代理自动设定 LANG 和 LC_ALL到C的区域设置。资源代理可以期待总是在C的区域设置里操作,不需要重置LANG和LC_ 环境变量。
9.3 测试运行进程
测试一个指定的进程(知道进程id)是否正在运行,通常的做法是发送一个0信号并捕获错误。比如:
if kill -s 0 `cat $daemon_pid_file`; then
ocf_log debug "Process is currently running"
else
ocf_log warn "Process is dead, removing pid file"
rm -f $daemon_pid_file
if
重要:一种远优于上述做法的例子是使用一个守护进程的客户端调用一个守护进程的功能,如5.3节 monitor action的例子。
9.4 设定master特性
有状态(master/slave)资源必须设定其自己的master特性,这些特性会为集群管理提供一些信息,帮助它确定谁是最合适提升为master角色的节点。
重要:多个实例拥有相同的master特性是可以接受的。在那个例子中,集群资源管理器可以自动选择一个资源代理去提升为master角色。如果所有的实例都有缺省的master分值0的话,集群管理器不提升任何实例。这样,重要的是,至少保持一个实例的master分值为正。
为此目标,crm_master 比较方便。它封装了crm_attribute 来设置其运行节点上的属性 master-$OCF_RESOURCE_INSTANCE为一个特定的值。集群管理器会将相应实例的这些改变转换为提升分数,其提升的特征基于此。
有状态的资源代理在monitor和notity行为时执行crm_master。
下面的例子假设foobar资源代理可以通过执行一个有返回值的执行文件测试应用的状态。这个返回值取决于是否:
- 资源是master角色或者是slave角色(被master完全捕获),或者
- 资源是slave角色,但是因为异步复制的原因,落后于master,或者
- 资源安全的停止了,或者
- 资源意外地失效了
foobar_monitor() {
local rc
# exit immediately if configuration is not valid
foobar_validate_all || exit $?
ocf_run frobnicate --test
# This example assumes the following exit code convention
# for frobnicate:
# 0: running, and fully caught up with master
# 1: gracefully stopped
# 2: running, but lagging behind master
# any other: error
case "$?" in
0)
rc=$OCF_SUCCESS
ocf_log debug "Resource is running"
# Set a high master preference. The current master
# will always get this, plus 1. Any current slaves
# will get a high preference so that if the master
# fails, they are next in line to take over.
crm_master -l reboot -v 100
;;
1)
rc=$OCF_NOT_RUNNING
ocf_log debug "Resource is not running"
# Remove the master preference for this node
crm_master -l reboot -D
;;
2)
rc=$OCF_SUCCESS
ocf_log debug "Resource is lagging behind master"
# Set a low master preference: if the master fails
# right now, and there is another slave that does
# not lag behind the master, its higher master
# preference will win and that slave will become
# the new master
crm_master -l reboot -v 5
;;
*)
ocf_log err "Resource has failed"
exit $OCF_ERR_GENERIC
esac
return $rc
}
没有评论:
发表评论