lc_hb.in

来自「lustre 1.6.5 source code」· IN 代码 · 共 645 行 · 第 1/2 页

IN
645
字号
#!/bin/bash## lc_hb - script for generating the Heartbeat HA software's#         configuration files################################################################################# Usageusage() {	cat >&2 <<EOFUsage:	`basename $0`	<-r HBver> <-n hostnames> [-v]			<-d target device> [-d target device...]	-r HBver		the version of Heartbeat software                        	The Heartbeat software versions which are curr-				ently supported are: hbv1 (Heartbeat version 1) 				and hbv2 (Heartbeat version 2).	-n hostnames            the nodenames of the primary node and its fail-				overs                        	Multiple nodenames are separated by colon (:)                        	delimeter. The first one is the nodename of the 				primary node, the others are failover nodenames.	-v			verbose mode	-d target device        the target device name and mount point                        	The device name and mount point are separated by				colon (:) delimeter. EOF	exit 1}# Get the library of functions. @scriptlibdir@/lc_common#****************************** Global variables ******************************## Heartbeat toolsHB_TOOLS_PATH=${HB_TOOLS_PATH:-"/usr/lib64/heartbeat"}	# Heartbeat tools pathCIB_GEN_SCRIPT=${HB_TOOLS_PATH}/haresources2cib.pyCL_STATUS=${CL_STATUS:-"/usr/bin/cl_status"}# Service directories and namesHARES_DIR=${HARES_DIR:-"${HA_DIR}/resource.d"}		# Heartbeat resourcesLUSTRE_SRV=${LUSTRE_SRV:-"Filesystem"}	# Service script provided by HeartbeatTMP_DIR=${HB_TMP_DIR}			# Temporary directoryHACF_TEMP=${TMP_DIR}/ha.cf.tempAUTHKEYS_TEMP=${TMP_DIR}/authkeys${FILE_SUFFIX}declare -a NODE_NAMES			# Node names in the failover group# Lustre target device names, service names and mount pointsdeclare -a TARGET_DEVNAMES TARGET_SRVNAMES TARGET_MNTPNTSdeclare -i TARGET_NUM=0			# Number of targets# Get and check the positional parametersVERBOSE_OUTPUT=falsewhile getopts "r:n:vd:" OPTION; do	case $OPTION in	r) 		HBVER_OPT=$OPTARG		if [ "${HBVER_OPT}" != "${HBVER_HBV1}" ] \		&& [ "${HBVER_OPT}" != "${HBVER_HBV2}" ]; then			echo >&2 $"`basename $0`: Invalid Heartbeat software" \				  "version - ${HBVER_OPT}!"			usage		fi		;;        n)		HOSTNAME_OPT=$OPTARG 		PRIM_NODENAME=`echo ${HOSTNAME_OPT} | awk -F":" '{print $1}'`		if [ -z "${PRIM_NODENAME}" ]; then			echo >&2 $"`basename $0`: Missing primary nodename!"			usage		fi		HOSTNAME_NUM=`echo ${HOSTNAME_OPT} | awk -F":" '{print NF}'`		if [ ${HOSTNAME_NUM} -lt 2 ]; then			echo >&2 $"`basename $0`: Missing failover nodenames!"			usage		fi		if [ "${HBVER_OPT}" = "${HBVER_HBV1}" -a ${HOSTNAME_NUM} -gt 2 ]		then			echo >&2 $"`basename $0`: Heartbeat version 1 can" \				  "only support 2 nodes!"			usage		fi		;;	v) 		VERBOSE_OUTPUT=true		;;        d)		DEVICE_OPT=$OPTARG 		TARGET_DEVNAMES[TARGET_NUM]=`echo ${DEVICE_OPT}|awk -F: '{print $1}'`		TARGET_MNTPNTS[TARGET_NUM]=`echo ${DEVICE_OPT}|awk -F: '{print $2}'`		if [ -z "${TARGET_DEVNAMES[TARGET_NUM]}" ]; then			echo >&2 $"`basename $0`: Missing target device name!"			usage		fi		if [ -z "${TARGET_MNTPNTS[TARGET_NUM]}" ]; then			echo >&2 $"`basename $0`: Missing mount point for target"\				  "${TARGET_DEVNAMES[TARGET_NUM]}!"			usage		fi		TARGET_NUM=$(( TARGET_NUM + 1 ))		;;        ?) 		usage 	esacdone# Check the required parametersif [ -z "${HBVER_OPT}" ]; then	echo >&2 $"`basename $0`: Missing -r option!"	usagefiif [ -z "${HOSTNAME_OPT}" ]; then	echo >&2 $"`basename $0`: Missing -n option!"	usagefiif [ -z "${DEVICE_OPT}" ]; then	echo >&2 $"`basename $0`: Missing -d option!"	usagefi# get_nodenames## Get all the node names in this failover groupget_nodenames() {	declare -i idx	local nodename_str nodename	nodename_str=`echo ${HOSTNAME_OPT}|awk '{split($HOSTNAME_OPT, a, ":")}\		      END {for (i in a) print a[i]}'`	idx=0	for nodename in ${nodename_str}        do		NODE_NAMES[idx]=${nodename}		idx=$idx+1        done	return 0}# check_remote_file host_name file## Run remote command to check whether @file exists in @host_namecheck_remote_file() {	local host_name=$1	local file_name=$2	if [ -z "${host_name}" ]; then		echo >&2 "`basename $0`: check_remote_file() error:"\			 "Missing hostname!"		return 1	fi	if [ -z "${file_name}" ]; then		echo >&2 "`basename $0`: check_remote_file() error:"\			 "Missing file name!"		return 1	fi	# Execute remote command to check the file 	${REMOTE} ${host_name} "[ -e ${file_name} ]"	if [ $? -ne 0 ]; then		echo >&2 "`basename $0`: check_remote_file() error:"\		"${file_name} does not exist in host ${host_name}!"		return 1	fi	return 0}# hb_running host_name# # Run remote command to check whether heartbeat service is running in @host_namehb_running() {	local host_name=$1	local ret_str	ret_str=`${REMOTE} ${host_name} "${CL_STATUS} hbstatus" 2>&1`	if [ $? -ne 0 ]; then		if [ "${ret_str}" = "${ret_str#*stop*}" ]; then			echo >&2 "`basename $0`: hb_running() error:"\			"remote command to ${host_name} error: ${ret_str}!"			return 2		else			return 1		fi	fi	return 0}# stop_heartbeat host_name## Run remote command to stop heartbeat service running in @host_namestop_heartbeat() {	local host_name=$1	local ret_str	ret_str=`${REMOTE} ${host_name} "/sbin/service heartbeat stop" 2>&1`	if [ $? -ne 0 ]; then		echo >&2 "`basename $0`: stop_heartbeat() error:"\		"remote command to ${host_name} error: ${ret_str}!"		return 1	fi	echo "`basename $0`: Heartbeat service is stopped on node ${host_name}."	return 0}# check_heartbeat## Run remote command to check each node's heartbeat servicecheck_heartbeat() {	declare -i idx	local OK	for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do		# Check Heartbeat configuration directory		if ! check_remote_file ${NODE_NAMES[idx]} ${HA_DIR}; then			echo >&2 "`basename $0`: check_heartbeat() error:"\			"Is Heartbeat package installed?"			return 1		fi		if [ "${HBVER_OPT}" = "${HBVER_HBV1}" ]; then			# Check mon configuration directory			if ! check_remote_file ${NODE_NAMES[idx]} ${MON_DIR}; then				echo >&2 "`basename $0`: check_heartbeat()"\				"error: Is mon package installed?"				return 1			fi		fi		if [ "${HBVER_OPT}" = "${HBVER_HBV2}" ]; then			# Check crm directory			if ! check_remote_file ${NODE_NAMES[idx]} ${CIB_DIR}; then				echo >&2 "`basename $0`: check_heartbeat()"\				"error: Is Heartbeat v2 package installed?"				return 1			fi		fi				# Check heartbeat service status		hb_running ${NODE_NAMES[idx]}		rc=$?		if [ "$rc" -eq "2" ]; then			return 1		elif [ "$rc" -eq "1" ]; then			verbose_output "Heartbeat service is stopped on"\			"node ${NODE_NAMES[idx]}."		elif [ "$rc" -eq "0" ]; then			OK=			echo -n "`basename $0`: Heartbeat service is running on"\			"${NODE_NAMES[idx]}, go ahead to stop the service and"\			"generate new configurations? [y/n]:"			read OK			if [ "${OK}" = "n" ]; then				echo "`basename $0`: New Heartbeat configurations"\				"are not generated."				return 2			fi			# Stop heartbeat service				stop_heartbeat ${NODE_NAMES[idx]}		fi	done	return 0}# get_srvname hostname target_devname## Get the lustre target server name from the node @hostnameget_srvname() {	local host_name=$1	local target_devname=$2	local target_srvname=	local ret_str	# Execute remote command to get the target server name	ret_str=`${REMOTE} ${host_name} \		"${TUNEFS} --print --verbose ${target_devname} | grep Target:" 2>&1`	if [ $? -ne 0 ]; then		echo "`basename $0`: get_srvname() error:" \		     "from host ${host_name} - ${ret_str}"		return 1	fi	if [ "${ret_str}" != "${ret_str#*Target: }" ]; then		ret_str=${ret_str#*Target: }		target_srvname=`echo ${ret_str} | awk '{print $1}'`	fi		if [ -z "${target_srvname}" ]; then		echo "`basename $0`: get_srvname() error: Cannot get the"\		     "server name of target ${target_devname} in ${host_name}!"		return 1	fi	echo ${target_srvname}	return 0} # get_srvnames## Get server names of all the Lustre targets in this failover groupget_srvnames() {	declare -i i	# Initialize the TARGET_SRVNAMES array	unset TARGET_SRVNAMES	# Get Lustre target service names	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do		TARGET_SRVNAMES[i]=$(get_srvname ${PRIM_NODENAME} \				     ${TARGET_DEVNAMES[i]})		if [ $? -ne 0 ]; then

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?