#!/bin/bash
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
#
# lc_hb - script for generating the Heartbeat HA software's
# configuration files
HBVER_OPT=$OPTARG
if [ "${HBVER_OPT}" != "${HBVER_HBV1}" ] \
&& [ "${HBVER_OPT}" != "${HBVER_HBV2}" ]; then
- echo >&2 $"`basename $0`: Invalid Heartbeat software" \
+ error_output "Invalid Heartbeat software" \
"version - ${HBVER_OPT}!"
usage
fi
HOSTNAME_OPT=$OPTARG
PRIM_NODENAME=`echo ${HOSTNAME_OPT} | awk -F":" '{print $1}'`
if [ -z "${PRIM_NODENAME}" ]; then
- echo >&2 $"`basename $0`: Missing primary nodename!"
+ error_output "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!"
+ error_output "Missing failover nodenames!"
usage
fi
if [ "${HBVER_OPT}" = "${HBVER_HBV1}" -a ${HOSTNAME_NUM} -gt 2 ]
then
- echo >&2 $"`basename $0`: Heartbeat version 1 can" \
+ error_output "Heartbeat version 1 can" \
"only support 2 nodes!"
usage
fi
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!"
+ error_output "Missing target device name!"
usage
fi
if [ -z "${TARGET_MNTPNTS[TARGET_NUM]}" ]; then
- echo >&2 $"`basename $0`: Missing mount point for target"\
+ error_output "Missing mount point for target"\
"${TARGET_DEVNAMES[TARGET_NUM]}!"
usage
fi
# Check the required parameters
if [ -z "${HBVER_OPT}" ]; then
- echo >&2 $"`basename $0`: Missing -r option!"
+ error_output "Missing -r option!"
usage
fi
if [ -z "${HOSTNAME_OPT}" ]; then
- echo >&2 $"`basename $0`: Missing -n option!"
+ error_output "Missing -n option!"
usage
fi
if [ -z "${DEVICE_OPT}" ]; then
- echo >&2 $"`basename $0`: Missing -d option!"
+ error_output "Missing -d option!"
usage
fi
local file_name=$2
if [ -z "${host_name}" ]; then
- echo >&2 "`basename $0`: check_remote_file() error:"\
+ error_output "check_remote_file():"\
"Missing hostname!"
return 1
fi
if [ -z "${file_name}" ]; then
- echo >&2 "`basename $0`: check_remote_file() error:"\
+ error_output "check_remote_file():"\
"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:"\
+ error_output "check_remote_file():"\
"${file_name} does not exist in host ${host_name}!"
return 1
fi
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:"\
+ error_output "hb_running():"\
"remote command to ${host_name} error: ${ret_str}!"
return 2
else
local host_name=$1
local ret_str
- ret_str=`${REMOTE} ${host_name} "/sbin/service heartbeat stop" 2>&1`
+ ret_str=$(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
+service heartbeat stop < /dev/null" 2>&1)
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: stop_heartbeat() error:"\
+ error_output "stop_heartbeat():"\
"remote command to ${host_name} error: ${ret_str}!"
return 1
fi
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:"\
+ error_output "check_heartbeat():"\
"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?"
+ error_output "check_heartbeat():"\
+ "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?"
+ error_output "check_heartbeat():"\
+ "Is Heartbeat v2 package installed?"
return 1
fi
fi
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`
+ ret_str=$(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
+${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}"
TARGET_SRVNAMES[i]=$(get_srvname ${PRIM_NODENAME} \
${TARGET_DEVNAMES[i]})
if [ $? -ne 0 ]; then
- echo >&2 "${TARGET_SRVNAMES[i]}"
+ error_output "${TARGET_SRVNAMES[i]}"
return 1
fi
done
touch ${TMP_DIR}$"/ha.cf."${NODE_NAMES[idx]}
scp ${HACF_LUSTRE} ${NODE_NAMES[idx]}:${HA_DIR}/
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to scp ha.cf file"\
+ error_output "Failed to scp ha.cf file"\
"to node ${NODE_NAMES[idx]}!"
return 1
fi
python ${CIB_GEN_SCRIPT} --stdout \
${HARES_LUSTRE} > ${CIB_LUSTRE}
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to generate cib.xml file"\
+ error_output "Failed to generate cib.xml file"\
"for node ${PRIM_NODENAME}!"
return 1
fi
/bin/cp -f ${HARES_LUSTRE} ${TMP_DIR}$"/haresources."${NODE_NAMES[idx]}
scp ${HARES_LUSTRE} ${NODE_NAMES[idx]}:${HA_DIR}/
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to scp haresources file"\
+ error_output "Failed to scp haresources file"\
"to node ${NODE_NAMES[idx]}!"
return 1
fi
if [ "${HBVER_OPT}" = "${HBVER_HBV2}" ]; then
scp ${CIB_LUSTRE} ${NODE_NAMES[idx]}:${CIB_DIR}/
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to scp cib.xml"\
+ error_output "Failed to scp cib.xml"\
"file to node ${NODE_NAMES[idx]}!"
return 1
fi
touch ${TMP_DIR}$"/authkeys."${NODE_NAMES[idx]}
scp -p ${AUTHKEYS_TEMP} ${NODE_NAMES[idx]}:${HA_DIR}/
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to scp authkeys file"\
+ error_output "Failed to scp authkeys file"\
"to node ${NODE_NAMES[idx]}!"
return 1
fi
${SCRIPT_GEN_MONCF} ${params}
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to generate mon.cf file"\
+ error_output "Failed to generate mon.cf file"\
"by using ${SCRIPT_GEN_MONCF}!"
return 1
fi
scp ${MONCF_LUSTRE} ${NODE_NAMES[idx]}:${MON_DIR}/
if [ $? -ne 0 ]; then
- echo >&2 "`basename $0`: Failed to scp mon.cf file"\
+ error_output "Failed to scp mon.cf file"\
"to node ${NODE_NAMES[idx]}!"
return 1
fi
# Here we expect the csv file
if [ $# -eq 0 ]; then
- echo >&2 "`basename $0`: Missing csv file!"
+ error_output "Missing csv file!"
usage
fi
+CSV_FILE=$1
+
# check_lvm_item index
#
# Check the items required for managing LVM device ${LVM_NAME[index]}
check_lvm_item() {
# Check argument
if [ $# -eq 0 ]; then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"Missing argument!"
return 1
fi
# Check hostname
if [ -z "${HOST_NAME[i]}" ]; then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"hostname item has null value!"
return 1
fi
if [ -z "${LVM_NAME[i]}" ] \
&& [ "${LINE_MARKER[i]}" != "${LV_MARKER}" -a "${OP_MODE[i]}" != "remove" ]
then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"LVM component name item has null value!"
return 1
fi
if [ -n "${OP_MODE[i]}" ] \
&& [ "${OP_MODE[i]}" != "create" -a "${OP_MODE[i]}" != "remove" ]
then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"Invalid operation mode item - \"${OP_MODE[i]}\"!"
return 1
fi
if [ -z "${OP_MODE[i]}" -o "${OP_MODE[i]}" = "create" ]; then
if [ "${LINE_MARKER[i]}" = "${VG_MARKER}" -a -z "${SIXTH_ITEM[i]}" ]
then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"pv paths item of vg ${LVM_NAME[i]} has null value!"
return 1
fi
if [ "${LINE_MARKER[i]}" = "${LV_MARKER}" ]; then
if [ -z "${SIXTH_ITEM[i]}" ]; then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"lv size item has null value!"
return 1
fi
if [ -z "${SEVENTH_ITEM[i]}" ]; then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"vg name item has null value!"
return 1
fi
get_lvm_items() {
# Check argument
if [ $# -eq 0 ]; then
- echo >&2 "`basename $0`: get_lvm_items() error: Missing csv file!"
+ error_output "get_lvm_items(): Missing csv file!"
return 1
fi
- CSV_FILE=$1
+ local CSV_FILE=$1
local LINE line_marker
local hostname
declare -i line_num=0
# Check some required items
if ! check_lvm_item $idx; then
- echo >&2 "`basename $0`: check_lvm_item() error:"\
+ error_output "check_lvm_item():"\
"Occurred on line ${line_num} in ${CSV_FILE}."
return 1
fi
fi
;;
*)
- echo >&2 "`basename $0`: construct_lvm_cmdline() error:"\
+ error_output "construct_lvm_cmdline():"\
"Invalid operation mode - \"${OP_MODE[i]}\"!"
return 1
;;
verbose_output "Configuring LVM devices in host ${host_name}..."
verbose_output "Configure command line is: \"${LVM_CMDLINE}\""
REMOTE_CMD[pid_num]="${REMOTE} ${host_name} \"${LVM_CMDLINE}\""
- ${REMOTE} ${host_name} "(${EXPORT_PATH} ${LVM_CMDLINE})" >&2 &
+ $REMOTE $host_name "export PATH=\$PATH:/sbin:/usr/sbin; $LVM_CMDLINE" &
REMOTE_PID[pid_num]=$!
let "pid_num += 1"
for ((pid_num = 0; pid_num < ${#REMOTE_PID[@]}; pid_num++)); do
wait ${REMOTE_PID[${pid_num}]}
if [ ${PIPESTATUS[0]} -ne 0 ]; then
- echo >&2 "`basename $0`: config_lvm() error: Failed"\
+ error_output "config_lvm(): Failed"\
"to execute \"${REMOTE_CMD[${pid_num}]}\"!"
failed_status=true
fi
# Main flow
# Check the csv file
-if ! check_file $1; then
- exit 1
-fi
+check_file $CSV_FILE || exit ${PIPESTATUS[0]}
# Get the list of nodes to be operated on
-NODES_TO_USE=$(get_nodelist)
-[ ${PIPESTATUS[0]} -ne 0 ] && echo >&2 "${NODES_TO_USE}" && exit 1
+NODES_TO_USE=$(get_nodelist) || error_exit ${PIPESTATUS[0]} "$NODES_TO_USE"
# Check the node list
check_nodelist ${NODES_TO_USE} || exit 1
#!/bin/bash
+
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
#
# lc_net - script for Lustre cluster network verification
#
# Here we expect the csv file
if [ $# -eq 0 ]; then
- echo >&2 $"`basename $0`: Missing csv file!"
+ error_output "Missing csv file!"
usage
fi
# Get the list of nodes to be operated on
NODES_TO_USE=$(get_nodelist)
- [ ${PIPESTATUS[0]} -ne 0 ] && echo >&2 "${NODES_TO_USE}" && return 1
+ [ ${PIPESTATUS[0]} -ne 0 ] && error_output "${NODES_TO_USE}" && return 1
# Check the node list
if [ -z "${NODES_TO_USE}" ]; then
# and get the IP address of this host from ping
HOST_IPADDRS[i]=$(ping_host ${HOST_NAMES[i]})
if [ ${PIPESTATUS[0]} -ne 0 ]; then
- echo >&2 "${HOST_IPADDRS[i]}"
+ error_output "${HOST_IPADDRS[i]}"
return 1
fi
cmd="ping -c1 ${HOST_NAMES[i]} 2>&1"
ret_str=$(${REMOTE} ${HOST_NAMES[i]} "${cmd}" 2>&1)
if [ ${PIPESTATUS[0]} -ne 0 -a -n "${ret_str}" ]; then
- echo >&2 "`basename $0`: remote_check() error:"\
+ error_output "remote_check():"\
"remote to ${HOST_NAMES[i]} error: ${ret_str}!"
return 1
fi
if [ -z "${ret_str}" ]; then
- echo >&2 "`basename $0`: remote_check() error:"\
+ error_output "remote_check():"\
"No results from ${HOST_NAMES[i]}! Check the network"\
"connectivity between local host and ${HOST_NAMES[i]}!"
return 1
# Check whether ${HOST_NAMES[i]} agrees with the local host
# about what its name is resolved to.
if [ "${ip_addr}" != "${HOST_IPADDRS[i]}" ]; then
- echo >&2 "`basename $0`: remote_check() error:"\
+ error_output "remote_check():"\
"Local host resolves ${HOST_NAMES[i]} to IP address"\
"\"${HOST_IPADDRS[i]}\", while its own resolution is"\
"\"${ip_addr}\". They are not the same!"