lc_common
来自「lustre 1.6.5 source code」· 代码 · 共 592 行 · 第 1/2 页
TXT
592 行
## vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:## lc_common - This file contains functions to be used by most or all# Lustre cluster config scripts.################################################################################## Remote command REMOTE=${REMOTE:-"ssh -x -q"}#REMOTE=${REMOTE:-"pdsh -S -R ssh -w"}export REMOTE# Lustre utilitiesCMD_PATH=${CMD_PATH:-"/usr/sbin"}MKFS=${MKFS:-"$CMD_PATH/mkfs.lustre"}TUNEFS=${TUNEFS:-"$CMD_PATH/tunefs.lustre"}LCTL=${LCTL:-"$CMD_PATH/lctl"}EXPORT_PATH=${EXPORT_PATH:-"PATH=\$PATH:/sbin:/usr/sbin;"}# Raid command pathRAID_CMD_PATH=${RAID_CMD_PATH:-"/sbin"}MDADM=${MDADM:-"$RAID_CMD_PATH/mdadm"}# Some scripts to be calledSCRIPTS_PATH=${CLUSTER_SCRIPTS_PATH:-"$(cd `dirname $0`; echo $PWD)"}MODULE_CONFIG=${SCRIPTS_PATH}/lc_modprobeVERIFY_CLUSTER_NET=${SCRIPTS_PATH}/lc_netGEN_HB_CONFIG=${SCRIPTS_PATH}/lc_hbGEN_CLUMGR_CONFIG=${SCRIPTS_PATH}/lc_clumanSCRIPT_VERIFY_SRVIP=${SCRIPTS_PATH}/lc_servipSCRIPT_GEN_MONCF=${SCRIPTS_PATH}/lc_monSCRIPT_CONFIG_MD=${SCRIPTS_PATH}/lc_mdSCRIPT_CONFIG_LVM=${SCRIPTS_PATH}/lc_lvm# Variables of HA softwareHBVER_HBV1="hbv1" # Heartbeat version 1HBVER_HBV2="hbv2" # Heartbeat version 2HATYPE_CLUMGR="cluman" # Cluster Manager# Configuration directories and filesHA_DIR=${HA_DIR:-"/etc/ha.d"} # Heartbeat configuration directoryMON_DIR=${MON_DIR:-"/etc/mon"} # mon configuration directoryCIB_DIR=${CIB_DIR:-"/var/lib/heartbeat/crm"} # cib.xml directoryHA_CF=${HA_DIR}/ha.cf # ha.cf fileHA_RES=${HA_DIR}/haresources # haresources fileHA_CIB=${CIB_DIR}/cib.xmlCLUMAN_DIR="/etc" # CluManager configuration directoryCLUMAN_CONFIG=${CLUMAN_DIR}/cluster.xmlCLUMAN_TOOLS_PATH=${CLUMAN_TOOLS_PATH:-"/usr/sbin"} # CluManager toolsCONFIG_CMD=${CONFIG_CMD:-"${CLUMAN_TOOLS_PATH}/redhat-config-cluster-cmd"}HB_TMP_DIR="/tmp/heartbeat" # Temporary directoryCLUMGR_TMP_DIR="/tmp/clumanager"TMP_DIRS="${HB_TMP_DIR} ${CLUMGR_TMP_DIR}"FS_TYPE=${FS_TYPE:-"lustre"} # Lustre filesystem typeFILE_SUFFIX=${FILE_SUFFIX:-".lustre"} # Suffix of the generated config files# Marker of the MD device lineMD_MARKER=${MD_MARKER:-"MD"}# Marker of the LVM device linePV_MARKER=${PV_MARKER:-"PV"}VG_MARKER=${VG_MARKER:-"VG"}LV_MARKER=${LV_MARKER:-"LV"}declare -a CONFIG_ITEM # Items in each line of the csv filedeclare -a NODE_NAME # Hostnames of nodes have been configured# Nodelist variablesUSE_ALLNODES=false # default is not to operate on all the nodesSPECIFIED_NODELIST="" # specified list of nodes to be operated onEXCLUDED_NODELIST="" # list of nodes to be excludedexport PATH=$PATH:$CMD_PATH:$SCRIPTS_PATH:$CLUMAN_TOOLS_PATH:$RAID_CMD_PATH:/sbin:/usr/sbin# verbose_output string# Output verbose information $stringverbose_output() { if ${VERBOSE_OUTPUT}; then echo "`basename $0`: $*" fi return 0}# Check whether the reomte command is pdshis_pdsh() { if [ "${REMOTE}" = "${REMOTE#*pdsh}" ]; then return 1 fi return 0}# check_file csv_file# Check the file $csv_filecheck_file() { # Check argument if [ $# -eq 0 ]; then echo >&2 "`basename $0`: check_file() error: Missing csv file!" return 1 fi CSV_FILE=$1 if [ ! -s ${CSV_FILE} ]; then echo >&2 "`basename $0`: check_file() error: ${CSV_FILE}"\ "does not exist or is empty!" return 1 fi return 0}# parse_line line# Parse a line in the csv fileparse_line() { # Check argument if [ $# -eq 0 ]; then echo >&2 "`basename $0`: parse_line() error: Missing argument!" return 1 fi declare -i i=0 # Index of the CONFIG_ITEM array declare -i length=0 declare -i idx=0 declare -i s_quote_flag=0 # Flag of the single quote character declare -i d_quote_flag=0 # Flag of the double quotes character local TMP_LETTER LINE LINE="$*" # Initialize the CONFIG_ITEM array unset CONFIG_ITEM # Get the length of the line length=${#LINE} i=0 while [ ${idx} -lt ${length} ]; do # Get a letter from the line TMP_LETTER=${LINE:${idx}:1} case "${TMP_LETTER}" in ",") if [ ${s_quote_flag} -eq 1 -o ${d_quote_flag} -eq 1 ] then CONFIG_ITEM[i]=${CONFIG_ITEM[i]}${TMP_LETTER} else i=$i+1 fi idx=${idx}+1 continue ;; "'") if [ ${s_quote_flag} -eq 0 ]; then s_quote_flag=1 else s_quote_flag=0 fi ;; "\"") if [ ${d_quote_flag} -eq 0 ]; then d_quote_flag=1 else d_quote_flag=0 fi ;; "
") idx=${idx}+1 continue ;; *) ;; esac CONFIG_ITEM[i]=${CONFIG_ITEM[i]}${TMP_LETTER} idx=${idx}+1 done # Extract the real value of each field # Remove surrounded double-quotes, etc. for ((idx = 0; idx <= $i; idx++)); do # Strip the leading and trailing space-characters CONFIG_ITEM[idx]=`expr "${CONFIG_ITEM[idx]}" : '[[:space:]]*\(.*\)[[:space:]]*$'` [ -z "${CONFIG_ITEM[idx]}" ] && continue # Remove the surrounded double-quotes while [ -z "`echo "${CONFIG_ITEM[idx]}"|sed -e 's/^".*"$//'`" ]; do CONFIG_ITEM[idx]=`echo "${CONFIG_ITEM[idx]}" | sed -e 's/^"//' -e 's/"$//'` done CONFIG_ITEM[idx]=`echo "${CONFIG_ITEM[idx]}" | sed -e 's/""/"/g'` done return 0}# fcanon name# If $name is a symbolic link, then display it's valuefcanon() { local NAME=$1 if [ -h "$NAME" ]; then readlink -f "$NAME" else echo "$NAME" fi}# configured_host host_name## Check whether the devices in $host_name has been configured or notconfigured_host() { local host_name=$1 declare -i i for ((i = 0; i < ${#NODE_NAME[@]}; i++)); do [ "${host_name}" = "${NODE_NAME[i]}" ] && return 0 done return 1}# remote_error fn_name host_addr ret_str# Verify the return result from remote commandremote_error() { local fn_name host_addr ret_str fn_name=$1 shift host_addr=$1 shift ret_str=$* if [ "${ret_str}" != "${ret_str#*connect:*}" ]; then echo >&2 "`basename $0`: ${fn_name}() error: ${ret_str}" return 0 fi if [ -z "${ret_str}" ]; then echo >&2 "`basename $0`: ${fn_name}() error:" \ "No results from remote!" \ "Check network connectivity between the local host and ${host_addr}!" return 0 fi return 1}# nid2hostname nid# Convert $nid to hostname of the lustre cluster nodenid2hostname() { local nid=$1 local host_name= local addr nettype ip_addr local ret_str addr=${nid%@*} [ "${nid}" != "${nid#*@*}" ] && nettype=${nid#*@} || nettype=tcp if [ -z "${addr}" ]; then echo "`basename $0`: nid2hostname() error: Invalid nid - \"${nid}\"!" return 1 fi case "${nettype}" in lo*) host_name=`hostname`;; elan*) # QsNet # FIXME: Parse the /etc/elanhosts configuration file to # convert ElanID to hostname ;; gm*) # Myrinet # FIXME: Use /usr/sbin/gmlndnid to find the hostname of # the specified GM Global node ID ;; ptl*) # Portals # FIXME: Convert portal ID to hostname ;; *) # tcp, o2ib, cib, openib, iib, vib, ra ip_addr=${addr} # Is it IP address or hostname? if [ -n "`echo ${ip_addr} | sed -e 's/\([0-9]\{1,3\}\.\)\{3,3\}[0-9]\{1,3\}//'`" ] then host_name=${ip_addr} echo ${host_name} return 0 fi # Execute remote command to get the host name ret_str=$(${REMOTE} ${ip_addr} "hostname" 2>&1 </dev/null) if [ ${PIPESTATUS[0]} -ne 0 -a -n "${ret_str}" ]; then
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?