diff --git a/tools/hb2openais.sh b/tools/hb2openais.sh.in similarity index 98% rename from tools/hb2openais.sh rename to tools/hb2openais.sh.in index 96cf348fbb..629e5d291b 100755 --- a/tools/hb2openais.sh +++ b/tools/hb2openais.sh.in @@ -1,895 +1,895 @@ #!/bin/sh # Copyright (C) 2008 Dejan Muhamedagic # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -. /etc/ha.d/shellfuncs +. @sysconfdir@/ha.d/shellfuncs . $HA_NOARCHBIN/utillib.sh PROG=`basename $0` # FIXME: once this is part of the package! PROGDIR=`dirname $0` echo "$PROGDIR" | grep -qs '^/' || { - test -f /usr/sbin/$PROG && - PROGDIR=/usr/sbin + test -f @sbindir@/$PROG && + PROGDIR=@sbindir@ test -f $HA_NOARCHBIN/$PROG && PROGDIR=$HA_NOARCHBIN } # the default syslog facility is not (yet) exported by heartbeat # to shell scripts # DEFAULT_HA_LOGFACILITY="daemon" export DEFAULT_HA_LOGFACILITY LOGD_CF=`findlogdcf /etc $HA_DIR` export LOGD_CF AIS_CONF=/etc/ais/openais.conf AIS_KEYF=/etc/ais/authkey -CIB=/var/lib/heartbeat/crm/cib.xml -CIBSIG=/var/lib/heartbeat/crm/cib.xml.sig -HOSTCACHE=/var/lib/heartbeat/hostcache -HB_UUID=/var/lib/heartbeat/hb_uuid -DONE_F=/var/run/heartbeat/.$PROG.conv_done +CIB=@HA_VARLIBDIR@/heartbeat/crm/cib.xml +CIBSIG=@HA_VARLIBDIR@/heartbeat/crm/cib.xml.sig +HOSTCACHE=@HA_VARLIBDIR@/heartbeat/hostcache +HB_UUID=@HA_VARLIBDIR@/heartbeat/hb_uuid +DONE_F=$HA_VARRUNDIR/heartbeat/.$PROG.conv_done BACKUPDIR=/var/tmp/`basename $PROG .sh`.backup BACKUP_FILES=" $CIB $CIBSIG $HOSTCACHE $HB_UUID $AIS_CONF " RM_FILES=" $CIBSIG $HOSTCACHE $HB_UUID " REMOTE_RM_FILES=" $CIB $CIBSIG $HOSTCACHE $HB_UUID " DIST_FILES=" $AIS_CONF $AIS_KEYF $DONE_F " MAN_TARF=/var/tmp/`basename $PROG .sh`.tar.gz [ `id -un` = dejan ] && MYSUDO=sudo : ${SSH_OPTS="-T"} usage() { cat</dev/null else ssh -T -o Batchmode=yes $1 true 2>/dev/null fi } findsshuser() { for u in "" $TRY_SSH; do rc=0 for n in `getnodes`; do [ "$node" = "$WE" ] && continue testsshuser $n $u || { rc=1 break } done if [ $rc -eq 0 ]; then echo $u return 0 fi done return 1 } newportinfo() { info "the port number for the multicast is set to 5405" info "please update your firewall rules (if any)" } changemediainfo() { info "openais uses multicast for communication" info "please make sure that your network infrastructure supports it" } multicastinfo() { info "multicast address for openais set to $1" } netaddrinfo() { info "network address for openais set to $1" } backup_files() { info "backing up $BACKUP_FILES to $BACKUPDIR" $DRY mkdir $BACKUPDIR || { echo sorry, could not create $BACKUPDIR directory echo please cleanup exit 1 } for f in $BACKUP_FILES; do $DRY cp -p $f $BACKUPDIR || { echo sorry, could not copy $f to $BACKUPDIR exit 1 } done } revert() { test -d $BACKUPDIR || { echo sorry, there is no $BACKUPDIR directory echo cannot revert exit 1 } for f in $BACKUP_FILES; do cp -p $BACKUPDIR/`basename $f` $f || { echo sorry, could not copy $BACKUPDIR/`basename $f` to $f } done } pls_press_enter() { cat< $AIS_CONF || fatal "cannot create $AIS_CONF" grep -wqs interface $AIS_CONF || fatal "no media found in $HA_CF" else openaisconf fi info "Generating a key for OpenAIS authentication ..." $DRY ais-keygen || fatal "cannot generate the key using ais-keygen" # remove various files which could get in a way $DRY rm -f $RM_FILES zap_nodes() { $MYSUDO python - <> sys.stderr, "ERROR: sorry, no nodes section in the CIB, cannot proceed" sys.exit(1) for c in nodes.childNodes: nodes.removeChild(c) s = skip_first(doc.toprettyxml()) tmp = write_tmp(s) print tmp EOF } # remove the nodes section from the CIB tmpfile=`zap_nodes` $MYSUDO [ -f "$tmpfile" ] || fatal "cannot remove the nodes section from the CIB" $DRY mv $tmpfile $CIB info "Done converting ha.cf to openais.conf" # # first part done (openais), on to the CIB analyze_cib() { info "Analyze the CIB..." $MYSUDO python - <> sys.stderr, "INFO: evms configuration found; conversion required" rc = 1 elif rsc_type == "Filesystem": if get_param(rsc,"fstype") == "ocfs2": print >> sys.stderr, "INFO: ocfs2 configuration found; conversion required" rc = 1 sys.exit(rc) EOF } convert_cib() { $MYSUDO python - <> sys.stderr, "Cannot read %s" % ans print >> sys.stderr, "We do need this input to continue." def nvpair(id,name,value): nvpair = doc.createElement("nvpair") nvpair.setAttribute("id",id + "_" + name) nvpair.setAttribute("name",name) nvpair.setAttribute("value",value) return nvpair def mk_lvm(rsc_id,volgrp): node = doc.createElement("primitive") node.setAttribute("id",rsc_id) node.setAttribute("type","LVM") node.setAttribute("provider","heartbeat") node.setAttribute("class","ocf") operations = doc.createElement("operations") node.appendChild(operations) mon_op = doc.createElement("op") operations.appendChild(mon_op) mon_op.setAttribute("id", rsc_id + "_mon") mon_op.setAttribute("name","monitor") interval = "120s" timeout = "60s" mon_op.setAttribute("interval", interval) mon_op.setAttribute("timeout", timeout) instance_attributes = doc.createElement("instance_attributes") instance_attributes.setAttribute("id", rsc_id + "_inst_attr") node.appendChild(instance_attributes) attributes = doc.createElement("attributes") instance_attributes.appendChild(attributes) attributes.appendChild(nvpair(rsc_id,"volgrpname",volgrp)) return node def mk_clone(id,ra_type,ra_class,prov): c = doc.createElement("clone") c.setAttribute("id",id + "-clone") meta = doc.createElement("meta_attributes") c.appendChild(meta) meta.setAttribute("id",id + "_meta") attributes = doc.createElement("attributes") meta.appendChild(attributes) attributes.appendChild(nvpair(id,"globally-unique","false")) attributes.appendChild(nvpair(id,"interleave","true")) p = doc.createElement("primitive") c.appendChild(p) p.setAttribute("id",id) p.setAttribute("type",ra_type) if prov: p.setAttribute("provider",prov) p.setAttribute("class",ra_class) operations = doc.createElement("operations") p.appendChild(operations) mon_op = doc.createElement("op") operations.appendChild(mon_op) mon_op.setAttribute("id", id + "_mon") mon_op.setAttribute("name","monitor") interval = "60s" timeout = "30s" mon_op.setAttribute("interval", interval) mon_op.setAttribute("timeout", timeout) return c def add_ocfs_clones(id): c1 = mk_clone(id+"-o2cb","o2cb","lsb","") c2 = mk_clone(id+"-dlm","controld","ocf","pacemaker") resources.appendChild(c1) resources.appendChild(c2) def mk_order(r1,r2): rsc_order = doc.createElement("rsc_order") rsc_order.setAttribute("id","rsc_order_"+r1+"_"+r2) rsc_order.setAttribute("from",r1) rsc_order.setAttribute("to",r2) rsc_order.setAttribute("type","before") rsc_order.setAttribute("symmetrical","true") return rsc_order def mk_colocation(r1,r2): rsc_colocation = doc.createElement("rsc_colocation") rsc_colocation.setAttribute("id","rsc_colocation_"+r1+"_"+r2) rsc_colocation.setAttribute("from",r1) rsc_colocation.setAttribute("to",r2) rsc_colocation.setAttribute("score","INFINITY") return rsc_colocation def add_ocfs_constraints(rsc,id): node = rsc.parentNode if node.tagName != "clone": node = rsc clone_id = node.getAttribute("id") c1 = mk_order(id+"-o2cb-clone",clone_id) c2 = mk_colocation(id+"-o2cb-clone",clone_id) constraints.appendChild(c1) constraints.appendChild(c2) c1 = mk_order(id+"-dlm-clone",id+"-o2cb-clone") c2 = mk_colocation(id+"-dlm-clone",id+"-o2cb-clone") constraints.appendChild(c1) constraints.appendChild(c2) def change_ocfs2_device(rsc): print >> sys.stderr, "The current device for ocfs2 depends on evms: %s"%get_param(rsc,"device") dev = get_input("Please supply the device where %s ocfs2 resource resides: "%rsc.getAttribute("id")) set_param(rsc,"device",dev) def stop_ocfs2(rsc): node = rsc.parentNode if node.tagName != "clone": node = rsc id = node.getAttribute("id") l = rsc.getElementsByTagName("meta_attributes") if l: meta = l[0] else: meta = doc.createElement("meta_attributes") meta.setAttribute("id",id + "_meta") node.appendChild(meta) attributes = doc.createElement("attributes") meta.appendChild(attributes) rm_param(rsc,"target_role") set_attribute("meta_attributes",node,"target_role","Stopped") def new_pingd_rsc(options,host_list): rsc_id = "pingd" c = mk_clone(rsc_id,"pingd","heartbeat","ocf") node = c.getElementsByTagName("primitive")[0] instance_attributes = doc.createElement("instance_attributes") instance_attributes.setAttribute("id", rsc_id + "_inst_attr") node.appendChild(instance_attributes) attributes = doc.createElement("attributes") instance_attributes.appendChild(attributes) attributes.appendChild(nvpair(rsc_id,"options",options)) return c def handle_pingd_respawn(): - f = open("/etc/ha.d/ha.cf", 'r') + f = open("$HA_CF", 'r') opts = '' ping_list = [] for l in f: s = l.split() if not s: continue if s[0] == "respawn" and s[2].find("pingd") > 0: opts = ' '.join(s[3:]) elif s[0] == "ping": ping_list.append(s[1]) f.close() return opts,' '.join(ping_list) CIB = "$CIB" doc = load_cib(CIB) xml_processnodes(doc,is_whitespace,rmnodes) resources = doc.getElementsByTagName("resources")[0] constraints = doc.getElementsByTagName("constraints")[0] if not resources: print >> sys.stderr, "ERROR: sorry, no resources section in the CIB, cannot proceed" sys.exit(1) if not constraints: print >> sys.stderr, "ERROR: sorry, no constraints section in the CIB, cannot proceed" sys.exit(1) opts,pingd_host_list = handle_pingd_respawn() if opts: clone = new_pingd_rsc(opts,pingd_host_list) resources.appendChild(clone) for rsc in doc.getElementsByTagName("primitive"): rsc_id = rsc.getAttribute("id") rsc_type = rsc.getAttribute("type") if rsc_type == "Evmsd": print >> sys.stderr, "INFO: removing the Evmsd resource" resources.removeChild(rsc) elif rsc_type == "EvmsSCC": print >> sys.stderr, "INFO: EvmsSCC resource is going to be replaced by LVM" vg = get_input("Please supply the name of the volume group corresponding to %s: "%rsc_id) node = mk_lvm(rsc_id,vg) parent = rsc.parentNode parent.removeChild(rsc) parent.appendChild(node) rsc.unlink() elif rsc_type == "pingd": if pingd_host_list: set_param(rsc,"host_list",pingd_host_list) elif rsc_type == "Filesystem": if get_param(rsc,"fstype") == "ocfs2": if get_param(rsc,"device").find("evms") > 0: change_ocfs2_device(rsc) id = rsc.getAttribute("id") print >> sys.stderr, "INFO: adding required cloned resources for %s"%id add_ocfs_clones(id) print >> sys.stderr, "INFO: adding constraints for %s"%id add_ocfs_constraints(rsc,id) print >> sys.stderr, "INFO: adding target_role=Stopped to %s"%id stop_ocfs2(rsc) s = skip_first(doc.toprettyxml()) tmp = write_tmp(s) print tmp EOF } part2() { intro_part2 || return 0 tmpfile=`convert_cib` $MYSUDO [ -f "$tmpfile" ] || fatal "failed to process the CIB" $DRY mv $tmpfile $CIB info "Processed the CIB successfully" } dcidle() { try_crmadmin=10 dc="" while [ -z "$dc" -a $try_crmadmin -gt 0 ]; do dc=`$MYSUDO crmadmin -D | awk '{print $NF}'` try_crmadmin=$((try_crmadmin-1)) done if [ x = x"$dc" ]; then echo "sorry, no dc found/elected" exit 1 fi maxcnt=60 cnt=0 while [ $cnt -lt $maxcnt ]; do stat=`$MYSUDO crmadmin -S $dc` ec=$? echo $stat | grep -qs S_IDLE && break [ "$1" = "-v" ] && echo $stat sleep 1 printf "." cnt=$((cnt+1)) done echo status: $stat echo waited: $cnt echo $stat | grep -qs S_IDLE } wait_cluster() { printf "waiting for crm to start." for i in 1 2 3 4 5; do for j in 1 2; do sleep 1; printf "." done done dcidle } tune_ocfs2() { cat<