3 # gen_clumanager_config.sh - script for generating the Red Hat's Cluster Manager
4 # HA software's configuration files
6 ################################################################################
12 Usage: `basename $0` <-n hostnames> <-d target device> <-s service addresses>
13 [-c heartbeat channels] [-o heartbeat options] [-v]
15 -n hostnames the nodenames of the primary node and its fail-
17 Multiple nodenames are separated by colon (:)
18 delimeter. The first one is the nodename of the
19 primary node, the others are failover nodenames.
20 -d target device the target device name and type
21 The name and type are separated by colon (:)
22 delimeter. The type values are: mgs, mdt, ost or
24 -s service addresses the IP addresses to failover
25 Multiple addresses are separated by colon (:)
27 -c heartbeat channels the methods to send/rcv heartbeats on
28 The default method is multicast, and multicast_
29 ipaddress is "225.0.0.11".
30 -o heartbeat options a "catchall" for other heartbeat configuration
39 SCRIPTS_PATH=${CLUSTER_SCRIPTS_PATH:-"./"}
40 SCRIPT_VERIFY_SRVIP=${SCRIPTS_PATH}$"verify_serviceIP.sh"
42 LUSTRE_SRV_SCRIPT=$"/etc/rc.d/init.d/lustre" # service script for lustre
44 TMP_DIR=$"/tmp/clumanager/" # temporary directory
45 CLUMGR_DIR=$"/etc/" # CluManager configuration directory
47 CONFIG_CMD=$"redhat-config-cluster-cmd"
49 declare -a NODE_NAMES # node names in the failover group
50 declare -a SRV_IPADDRS # service IP addresses
52 # Get and check the positional parameters
53 while getopts "n:d:s:c:o:v" OPTION; do
57 HOSTNAME_NUM=`echo ${HOSTNAME_OPT} | awk -F":" '{print NF}'`
58 if [ ${HOSTNAME_NUM} -lt 2 ]; then
59 echo >&2 $"`basename $0`: Lack failover nodenames!"
65 TARGET_DEV=`echo ${DEVICE_OPT} | awk -F":" '{print $1}'`
66 TARGET_TYPE=`echo ${DEVICE_OPT} | awk -F":" '{print $2}'`
67 if [ -z "${TARGET_TYPE}" ]; then
68 echo >&2 $"`basename $0`: Lack target device type!"
71 if [ "${TARGET_TYPE}" != "mgs" ]&&[ "${TARGET_TYPE}" != "mdt" ]\
72 &&[ "${TARGET_TYPE}" != "ost" ]&&[ "${TARGET_TYPE}" != "mgs_mdt" ]
74 echo >&2 $"`basename $0`: Invalid target device type" \
84 HBCHANNEL_OPT=`echo "${HBCHANNEL_OPT}" | sed 's/^"//' \
86 if [ -n "${HBCHANNEL_OPT}" ] \
87 && [ "${HBCHANNEL_OPT}" = "${HBCHANNEL_OPT#*broadcast*}" ] \
88 && [ "${HBCHANNEL_OPT}" = "${HBCHANNEL_OPT#*multicast*}" ]; then
89 echo >&2 $"`basename $0`: Invalid Heartbeat channel" \
96 HBOPT_OPT=`echo "${HBOPT_OPT}" | sed 's/^"//' | sed 's/"$//'`
106 # Check the required parameters
107 if [ -z "${HOSTNAME_OPT}" ]; then
108 echo >&2 $"`basename $0`: Lack -n option!"
112 if [ -z "${DEVICE_OPT}" ]; then
113 echo >&2 $"`basename $0`: Lack -d option!"
117 if [ -z "${SRVADDR_OPT}" ]; then
118 echo >&2 $"`basename $0`: Lack -s option!"
122 # Output verbose informations
124 if [ "${VERBOSE_OPT}" = "yes" ]; then
125 echo "`basename $0`: $*"
132 # Get all the node names in this failover group
134 PRIM_NODENAME=`echo ${HOSTNAME_OPT} | awk -F":" '{print $1}'`
137 local nodename_str nodename
139 nodename_str=`echo ${HOSTNAME_OPT}|awk '{split($HOSTNAME_OPT, a, ":")}\
140 END {for (i in a) print a[i]}'`
142 for nodename in ${nodename_str}
144 NODE_NAMES[idx]=${nodename}
151 # get_check_srvIPaddrs
153 # Get and check all the service IP addresses in this failover group
154 get_check_srvIPaddrs() {
157 local srvIPaddr_str srvIPaddr
159 srvIPaddr_str=`echo ${SRVADDR_OPT}|awk '{split($SRVADDR_OPT, a, ":")}\
160 END {for (i in a) print a[i]}'`
162 for srvIPaddr in ${srvIPaddr_str}
164 SRV_IPADDRS[idx]=${srvIPaddr}
168 for ((idx = 0; idx < ${#SRV_IPADDRS[@]}; idx++)); do
169 for ((i = 0; i < ${#NODE_NAMES[@]}; i++)); do
170 # Check service IP address
171 verbose_output "Verifying service IP ${SRV_IPADDRS[idx]} and" \
172 "real IP of host ${NODE_NAMES[i]} are in the" \
174 if ! ${SCRIPT_VERIFY_SRVIP} ${SRV_IPADDRS[idx]} ${NODE_NAMES[i]}
187 # Run pdsh command to stop each node's clumanager service
190 local nodename_str=${PRIM_NODENAME}
192 for ((idx = 1; idx < ${#NODE_NAMES[@]}; idx++)); do
193 nodename_str=${nodename_str}$","${NODE_NAMES[idx]}
196 ${PDSH} -w ${nodename_str} /sbin/service clumanager stop
197 if [ $? -ne 0 ]; then
198 echo >&2 "`basename $0`: stop_clumanager() error:"\
199 "Fail to execute pdsh command!"
206 # check_retval retval
208 # Check the return value of redhat-config-cluster-cmd
210 if [ $1 -ne 0 ]; then
211 echo >&2 "`basename $0`: Fail to run ${CONFIG_CMD}!"
220 # Run redhat-config-cluster-cmd to create the cluster.xml file
224 local hbopt_str hbopt
226 # Run redhat-config-cluster-cmd to generate cluster.xml
228 if [ "${HBCHANNEL_OPT}" != "${HBCHANNEL_OPT#*broadcast*}" ]; then
229 ${CONFIG_CMD} --clumembd --broadcast=yes
230 if ! check_retval $?; then
233 elif [ "${HBCHANNEL_OPT}" != "${HBCHANNEL_OPT#*multicast*}" ]; then
234 mcast_IPaddr=`echo ${HBCHANNEL_OPT} | awk '{print $2}'`
235 if [ -n "${mcast_IPaddr}" ]; then
236 ${CONFIG_CMD} --clumembd --multicast=yes\
237 --multicast_ipaddress=${mcast_IPaddr}
238 if ! check_retval $?; then
245 ${CONFIG_CMD} --cluster --name='${TARGET_TYPE} failover group'
246 if ! check_retval $?; then
251 for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do
252 ${CONFIG_CMD} --add_member --name=${NODE_NAMES[idx]}
253 if ! check_retval $?; then
258 # Add failoverdomain tag
259 ${CONFIG_CMD} --add_failoverdomain --name=${TARGET_TYPE}-domain
260 if ! check_retval $?; then
264 for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do
265 ${CONFIG_CMD} --failoverdomain=${TARGET_TYPE}-domain\
266 --add_failoverdomainnode --name=${NODE_NAMES[idx]}
267 if ! check_retval $?; then
273 ${CONFIG_CMD} --add_service --name=${TARGET_TYPE}-service
274 if ! check_retval $?; then
278 ${CONFIG_CMD} --service=${TARGET_TYPE}-service \
279 --userscript=${LUSTRE_SRV_SCRIPT}
280 if ! check_retval $?; then
284 ${CONFIG_CMD} --service=${TARGET_TYPE}-service \
285 --failoverdomain=${TARGET_TYPE}-domain
286 if ! check_retval $?; then
290 for ((idx = 0; idx < ${#SRV_IPADDRS[@]}; idx++)); do
291 ${CONFIG_CMD} --service=mgs-service \
292 --add_service_ipaddress --ipaddress=${SRV_IPADDRS[idx]}
293 if ! check_retval $?; then
299 if [ -n "${HBOPT_OPT}"]; then
300 hbopt_str=`echo ${HBOPT_OPT}|awk '{split($HBOPT_OPT, a, ":")}\
301 END {for (i in a) print a[i]}'`
303 for hbopt in ${hbopt_str}
305 ${CONFIG_CMD} ${hbopt}
306 if ! check_retval $?; then
318 # Create the cluster.xml file and scp it to the each node's /etc/
320 CONFIG_PRIMNODE=${TMP_DIR}$"cluster.xml."${PRIM_NODENAME}
323 if [ -e ${CONFIG_PRIMNODE} ]; then
324 verbose_output "${CONFIG_PRIMNODE} already exists."
328 # Run redhat-config-cluster-cmd to generate cluster.xml
329 verbose_output "Creating cluster.xml file for" \
330 "${PRIM_NODENAME} failover group hosts..."
331 if ! gen_cluster_xml; then
336 /bin/cp -f ${CLUMGR_DIR}cluster.xml ${CONFIG_PRIMNODE}
338 # scp the cluster.xml file to all the nodes
339 verbose_output "Remote copying cluster.xml file to" \
340 "${PRIM_NODENAME} failover group hosts..."
341 for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do
342 touch ${TMP_DIR}$"cluster.xml."${NODE_NAMES[idx]}
343 scp ${CONFIG_PRIMNODE} ${NODE_NAMES[idx]}:${CLUMGR_DIR}cluster.xml
344 if [ $? -ne 0 ]; then
345 echo >&2 "`basename $0`: Fail to scp cluster.xml file"\
346 "to node ${NODE_NAMES[idx]}!"
356 # Get all the node names
357 if ! get_nodenames; then
361 # Get and check all the service IP addresses
362 if ! get_check_srvIPaddrs; then
366 # Stop clumanager services
367 verbose_output "Stopping clumanager service in the ${PRIM_NODENAME}"\
368 "failover group hosts..."
369 if ! stop_clumanager; then
374 # Generate configuration files
375 if ! create_config; then