From 63d544e9b0ddc2c473d0e35b92f4b5e40bb9a7c0 Mon Sep 17 00:00:00 2001 From: yujian Date: Tue, 16 Sep 2008 08:08:37 +0000 Subject: [PATCH] Branch b1_8_gate b=14095 i=nathan.rutman i=brian 1) add lustre_start utility to start or stop multiple Lustre servers from a CSV file 2) fix the utility path issue in bug 14094 3) use 'error_output()' to format error messages 4) move common variables and functions to lc_common 5) fix the "lustre_config -h" issue in bug 14133 6) fix the module_opts issue in bug 14092 7) remove the duplicates from checking lnet connectivity to MGS node --- lustre/scripts/lc_hb.in | 64 +++++++++++++++++++++++++----------------------- lustre/scripts/lc_lvm.in | 37 ++++++++++++++-------------- lustre/scripts/lc_net.in | 15 +++++++----- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/lustre/scripts/lc_hb.in b/lustre/scripts/lc_hb.in index 0fa1fb0..08a8661 100644 --- a/lustre/scripts/lc_hb.in +++ b/lustre/scripts/lc_hb.in @@ -1,4 +1,7 @@ #!/bin/bash + +# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4: + # # lc_hb - script for generating the Heartbeat HA software's # configuration files @@ -62,7 +65,7 @@ while getopts "r:n:vd:" OPTION; do 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 @@ -71,17 +74,17 @@ while getopts "r:n:vd:" OPTION; do 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 @@ -94,11 +97,11 @@ while getopts "r:n:vd:" OPTION; do 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 @@ -111,17 +114,17 @@ done # 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 @@ -152,13 +155,13 @@ check_remote_file() { 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 @@ -166,7 +169,7 @@ check_remote_file() { # 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 @@ -184,7 +187,7 @@ hb_running() { 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 @@ -202,9 +205,10 @@ stop_heartbeat() { 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 @@ -223,7 +227,7 @@ check_heartbeat() { 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 @@ -231,8 +235,8 @@ check_heartbeat() { 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 @@ -240,8 +244,8 @@ check_heartbeat() { 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 @@ -284,8 +288,8 @@ get_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` + 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}" @@ -321,7 +325,7 @@ get_srvnames() { 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 @@ -397,7 +401,7 @@ create_hacf() { 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 @@ -444,7 +448,7 @@ create_haresources() { 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 @@ -455,7 +459,7 @@ create_haresources() { /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 @@ -463,7 +467,7 @@ create_haresources() { 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 @@ -491,7 +495,7 @@ create_authkeys() { 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 @@ -547,7 +551,7 @@ create_moncf() { ${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 @@ -560,7 +564,7 @@ create_moncf() { 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 diff --git a/lustre/scripts/lc_lvm.in b/lustre/scripts/lc_lvm.in index 98248d7..3f0d616 100644 --- a/lustre/scripts/lc_lvm.in +++ b/lustre/scripts/lc_lvm.in @@ -162,17 +162,19 @@ shift `expr $OPTIND - 1` # 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 @@ -181,7 +183,7 @@ check_lvm_item() { # 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 @@ -190,7 +192,7 @@ check_lvm_item() { 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 @@ -199,7 +201,7 @@ check_lvm_item() { 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 @@ -208,20 +210,20 @@ check_lvm_item() { 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 @@ -237,11 +239,11 @@ check_lvm_item() { 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 @@ -280,7 +282,7 @@ get_lvm_items() { # 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 @@ -473,7 +475,7 @@ construct_lvm_cmdline() { fi ;; *) - echo >&2 "`basename $0`: construct_lvm_cmdline() error:"\ + error_output "construct_lvm_cmdline():"\ "Invalid operation mode - \"${OP_MODE[i]}\"!" return 1 ;; @@ -511,7 +513,7 @@ config_lvm_devs() { 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" @@ -553,7 +555,7 @@ config_lvm() { 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 @@ -569,13 +571,10 @@ config_lvm() { # 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 diff --git a/lustre/scripts/lc_net.in b/lustre/scripts/lc_net.in index d618c69..16196d3 100644 --- a/lustre/scripts/lc_net.in +++ b/lustre/scripts/lc_net.in @@ -1,4 +1,7 @@ #!/bin/bash + +# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4: + # # lc_net - script for Lustre cluster network verification # @@ -58,7 +61,7 @@ shift `expr $OPTIND - 1` # Here we expect the csv file if [ $# -eq 0 ]; then - echo >&2 $"`basename $0`: Missing csv file!" + error_output "Missing csv file!" usage fi @@ -76,7 +79,7 @@ get_hostnames() { # 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 @@ -133,7 +136,7 @@ local_check() { # 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 @@ -153,13 +156,13 @@ remote_check() { 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 @@ -177,7 +180,7 @@ remote_check() { # 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!" -- 1.8.3.1