diff --git a/scripts/crm-fence-peer.9.sh b/scripts/crm-fence-peer.9.sh index b326a165..552d044c 100755 --- a/scripts/crm-fence-peer.9.sh +++ b/scripts/crm-fence-peer.9.sh @@ -80,6 +80,33 @@ restrict_existing_constraint_further() done } +# From ocf-shellfuncs +# usage: ocf_version_cmp VER1 VER2 +# version strings can contain digits, dots, and dashes +# must start and end with a digit +# returns: +# 0: VER1 smaller (older) than VER2 +# 1: versions equal +# 2: VER1 greater (newer) than VER2 +# 3: bad format +ocf_version_cmp() { + ocf_is_ver "$1" || return 3 + ocf_is_ver "$2" || return 3 + local v1=$1 + local v2=$2 + + sort_version="sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n" + older=$( (echo "$v1"; echo "$v2") | $sort_version | head -1 ) + + if [[ "$v1" == "$v2" ]]; then + return 1 + elif [[ "$v1" == "$older" ]]; then + return 0 + else + return 2 # -1 would look funny in shell ;-) + fi +} + # set CIB_file= in environment, unless you want to grab the "live" one. # # I'd like to use the optional prefix filter on the constraint id, @@ -691,6 +718,15 @@ existing_constraint_rejects_me() setup_new_constraint() { new_constraint=""$'\n' + + if [[ -z "$role" ]]; then + if $OCF_1_1_SUPPORT ; then + role="Promoted" + else + role="Master" + fi + fi + # double negation: do not run but with my data. new_constraint+=" "$'\n' @@ -1444,7 +1480,6 @@ fi # apply defaults: : "== fencing_attribute == ${fencing_attribute:="#uname"}" : "== id_prefix == ${id_prefix:="drbd-fence-by-handler"}" -: "== role == ${role:="Master"}" # defaults suitable for most cases : "== net_hickup_time == ${net_hickup_time:=0}" @@ -1455,6 +1490,12 @@ fi : "== lock_file == ${lock_file}" : "== lock_dir == ${lock_dir}" +OCF_1_1_SUPPORT=false +ocf_version_cmp "$crm_feature_set" "3.10.0" +res=$? +if [[ $res -eq 2 ]] || [[ $res -eq 1 ]]; then + OCF_1_1_SUPPORT=true +fi # check envars normally passed in by drbdadm # TODO DRBD_CONF is also passed in. we may need to use it in the diff --git a/scripts/drbd.ocf b/scripts/drbd.ocf index 34d208f2..1872c1c9 100755 --- a/scripts/drbd.ocf +++ b/scripts/drbd.ocf @@ -105,6 +105,18 @@ if ! command -v ocf_is_true &> /dev/null ; then } fi +if ! command -v ocf_promotion_score &> /dev/null ; then + ocf_promotion_score() { + ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.10.0" + res=$? + if [ $res -eq 2 ] || [ $res -eq 1 ] || ! have_binary "crm_master"; then + ${HA_SBIN_DIR}/crm_attribute -p ${OCF_RESOURCE_INSTANCE} $@ + else + ${HA_SBIN_DIR}/crm_master -l reboot $@ + fi + } +fi + # Defaults OCF_RESKEY_drbdconf_default="/etc/drbd.conf" OCF_RESKEY_unfence_extra_args_default="--quiet --flock-required --flock-timeout 0 --unfence-only-if-owner-match" @@ -217,15 +229,32 @@ fi # end of debugging aid ####################################################################### +# OCF 1.1 supports new role "promoted" and "unpromoted" instead of "Master" and "Slave" +# +OCF_1_1_SUPPORT=false +ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.10.0" +res=$? +if [ $res -eq 2 ] || [ $res -eq 1 ]; then + OCF_1_1_SUPPORT=true +fi + meta_data() { + if $OCF_1_1_SUPPORT ; then + actions=' +' + else + actions=' +' + fi + cat < - + -1.0 +1.1 This resource agent manages a DRBD resource as a master/slave resource. @@ -472,8 +501,7 @@ to be generated after the failover of a "healthy" DRBD. - - +$actions @@ -604,9 +632,9 @@ do_drbdadm() { unset current_master_score get_current_master_score() { - # only call crm_master once + # only call get crm master once [[ ${current_master_score+set} ]] || - current_master_score=$(crm_master -q -l reboot -G 2>/dev/null) + current_master_score=$(ocf_promotion_score -q -G 2>/dev/null) # return value of this function: # true if master_score is present # false if master_score is not present @@ -619,13 +647,13 @@ set_master_score() { if [[ $1 -le 0 ]]; then remove_master_score else - do_cmd_CRM_meta_timeout ${HA_SBIN_DIR}/crm_master -Q -l reboot -v $1 && + do_cmd_CRM_meta_timeout ocf_promotion_score -Q -v $1 && current_master_score=$1 fi } remove_master_score() { - do_cmd_CRM_meta_timeout ${HA_SBIN_DIR}/crm_master -l reboot -D + do_cmd_CRM_meta_timeout ocf_promotion_score -D current_master_score="" }