Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Raid1.backup 2014-09-28 19:07:15.436006749 -0400
- +++ Raid1 2014-10-09 08:33:32.447596671 -0400
- @@ -43,7 +43,7 @@
- usage() {
- cat <<-EOT
- - usage: $0 {start|stop|status|monitor|validate-all|usage|meta-data}
- + usage: $0 {start|stop|status|monitor|promote|demote|notify|validate-all|usage|meta-data}
- EOT
- }
- @@ -132,6 +132,26 @@
- <content type="boolean" default="false" />
- </parameter>
- +
- +<parameter name="master_slave_mode" unique="0" required="0">
- +<longdesc lang="en">
- +Allows for ms style configuration which activates the resource on both nodes
- +with master being readwrite and slave being readonly.
- +</longdesc>
- +<shortdesc lang="en">allows for ms style configurations.</shortdesc>
- +<content type="boolean" default="false" />
- +</parameter>
- +
- +
- +<parameter name="preferred_master" unique="0" required="0">
- +<longdesc lang="en">
- +Allows for ms style configuration which activates the resource on both nodes
- +with master being readwrite and slave being readonly.
- +</longdesc>
- +<shortdesc lang="en">allows for ms style configurations.</shortdesc>
- +<content type="string" default="" />
- +</parameter>
- +
- </parameters>
- <actions>
- @@ -141,11 +161,198 @@
- <action name="monitor" depth="0" timeout="20s" interval="10" />
- <action name="validate-all" timeout="5" />
- <action name="meta-data" timeout="5" />
- +<action name="promote" timeout="20" />
- +<action name="demote" timeout="20" />
- +<action name="notify" timeout="20" />
- +
- </actions>
- </resource-agent>
- END
- }
- +raid1_notify() {
- + local type_op="${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation}"
- + local md=`echo $MDDEV | sed 's,/dev/,,'`
- + ocf_log info "Received '$type_op' notification."
- + case "$type_op" in
- + 'post-promote')
- + ocf_log info "Received '$type_op' notification for node(s): $OCF_RESKEY_CRM_meta_notify_promote_uname"
- + # If the notification is not for this node, then update the remote target group state
- + for i in $OCF_RESKEY_CRM_meta_notify_promote_uname; do
- + master_host="$i"
- + if [ `uname -n` = $master_host ]; then
- + if [ `cat /sys/block/$md/md/array_state` = readonly ]; then
- + ocf_run $MDADM --misc --readwrite $MDDEV || exit $OCF_ERR_GENERIC
- + fi
- + ocf_log info "Ignoring my own promotion. Nothing to do"
- + return $OCF_SUCCESS
- + fi
- + if [ `cat /sys/block/$md/md/array_state` != readonly ]; then
- + ocf_run $MDADM --misc -o $MDDEV || exit $OCF_ERR_GENERIC
- + else
- + return $OCF_SUCCESS
- + fi
- + done
- + ;;
- + 'post-demote')
- + ocf_log info "Received '$type_op' notification for node(s): $OCF_RESKEY_CRM_meta_notify_demote_uname"
- + # If the notification is not for this node, then update the remote target group state
- + for i in $OCF_RESKEY_CRM_meta_notify_demote_uname; do
- + master_host="$i"
- + if [ `uname -n` = $master_host ]; then
- + if [ `cat /sys/block/$md/md/array_state` != readonly ]; then
- + ocf_run $MDADM --misc -o $MDDEV || exit $OCF_ERR_GENERIC
- + fi
- + ocf_log info "Ignoring my own promotion. Nothing to do"
- + return $OCF_SUCCESS
- + fi
- + if [ `cat /sys/block/$md/md/array_state` = readonly ]; then
- + ocf_run $MDADM --misc --readwrite $MDDEV || exit $OCF_ERR_GENERIC
- + else
- + ocf_log info "Ignoring $master_host being demoted Nothing to do"
- + return $OCF_SUCCESS
- + fi
- + done
- + ;;
- + esac
- + return $OCF_SUCCESS
- +}
- +
- +
- +raid1_promote() {
- + raid1_status
- + local rc=${?}
- + case "${rc}" in
- + "${OCF_SUCCESS}")
- + # Running as Slave; normal, expected behavior
- + ocf_log info "raid1_promote() -> Resource is" \
- + "currently running as Slave."
- + ;;
- + "${OCF_RUNNING_MASTER}")
- + # Already running as Master; nothing to do
- + ocf_log info "raid1_promote() -> Resource is" \
- + "currently running as Master"
- + return ${OCF_SUCCESS}
- + ;;
- + "${OCF_NOT_RUNNING}")
- + # Not running; getting a demote action in this state is unexpected
- + ocf_log err "Resource is currently not running."
- + exit ${OCF_ERR_GENERIC}
- + ;;
- + *)
- + # Failed resource; let the cluster manager recover
- + ocf_log err "Unexpected error, cannot demote."
- + exit ${rc}
- + ;;
- + esac
- +
- + if ocf_is_true ${OCF_RESKEY_master_slave_mode}; then
- + # Set the mddev to readwrite on the slave
- + ocf_log info "raid1_promote() -> Setting $MDDEV to rw"
- + ocf_run $MDADM --misc --readwrite $MDDEV || exit ${OCF_ERR_GENERIC}
- + crm_master -l reboot -v 100
- + else
- + ocf_log err "Need to configure master slave mode before trying to promote/demote"
- + exit ${OCF_ERR_CONFIGURED}
- + fi
- +
- + # After the resource has been demoted, check whether the demotion worked
- + while true; do
- + raid1_status
- + if [ ${?} -ne ${OCF_RUNNING_MASTER} ]; then
- + ocf_log info "raid1_promote() -> Resource still" \
- + "awaiting promotion."
- + sleep 5
- + else
- + ocf_log info "Resource was promoted successfully."
- + break
- + fi
- + done
- +
- + # Only return $OCF_SUCCESS if _everything_ succeeded as expected
- + return ${OCF_SUCCESS}
- +}
- +
- +
- +raid1_demote() {
- + raid1_status
- + local rc=${?}
- + case "${rc}" in
- + "${OCF_RUNNING_MASTER}")
- + # Running as Master; normal, expected behavior
- + ocf_log info "raid1_demote() -> Resource is" \
- + "currently running as Master."
- + ;;
- + "${OCF_SUCCESS}")
- + # Already running as Slave; nothing to do
- + ocf_log info "raid1_demote() -> Resource is" \
- + "currently running as Slave."
- + return ${OCF_SUCCESS}
- + ;;
- + "${OCF_NOT_RUNNING}")
- + # Not running; getting a demote action in this state is unexpected
- + ocf_log err "Resource is currently not running."
- + exit ${OCF_ERR_GENERIC}
- + ;;
- + *)
- + # Failed resource; let the cluster manager recover
- + ocf_log err "Unexpected error, cannot demote."
- + exit ${rc}
- + ;;
- + esac
- +
- + if ocf_is_true ${OCF_RESKEY_master_slave_mode}; then
- + if [ ! `$MDADM --detail $MDDEV | grep -e '(Check Status*|Resync Status*)'` ]; then
- + # Set the mddev to readonly on the slave
- + ocf_log info "raid1_demote() -> Setting $MDDEV to ro"
- + ocf_run $MDADM --misc -o $MDDEV || exit ${OCF_ERR_GENERIC}
- + crm_master -l reboot -D
- + else
- + ocf_log err "Will not demote while operation is in progress on $MDDEV"
- + exit ${OCF_ERR_GENERIC}
- + fi
- + else
- + ocf_log err "Need to configure master slave mode before trying to demote"
- + exit ${OCF_ERR_CONFIGURED}
- + fi
- +
- + # After the resource has been demoted, check whether the demotion worked
- + while true; do
- + raid1_status
- + if [ ${?} -eq ${OCF_RUNNING_MASTER} ]; then
- + ocf_log info "raid1_demote() -> Resource still" \
- + "awaiting demotion."
- + sleep 5
- + else
- + ocf_log info "Resource was demoted successfully."
- + break
- + fi
- + done
- +
- + # Only return $OCF_SUCCESS if _everything_ succeeded as expected
- + return ${OCF_SUCCESS}
- +}
- +
- +check_mdadm_version() {
- + if [ "$OCF_RESKEY_master_slave_mode" != "false" ]; then
- + local v=`$MDADM --version 2>&1 | cut -d"-" -f2 | cut -d"v" -f2`
- + if [[ `echo $v` =~ 3.3.[0-9] || `echo $v` =~ 3.3 ]]; then
- + ocf_log info "mdadm `echo $v` found and ms mode is enabled!"
- + else
- + ocf_log err "mdadm version => 3.3 required"
- + return ${OCF_ERR_GENERIC}
- + fi
- + fi
- + return $OCF_SUCCESS
- +}
- +
- +get_raid1_state() {
- + local mddev=$1
- + local md=`echo $mddev | sed 's,/dev/,,'`
- + local outp
- + outp=`cat /sys/block/$md/md/array_state`
- + echo "$outp"
- +}
- udev_settle() {
- if ocf_is_true $WAIT_FOR_UDEV; then
- udevadm settle $*
- @@ -181,15 +388,26 @@
- }
- md_assemble() {
- - local mddev=$1
- - $MDADM --assemble $mddev --config=$RAIDCONF $MDADM_HOMEHOST
- - udev_settle --exit-if-exists=$mddev
- + local mddev=$1
- + if [ "$OCF_RESKEY_master_slave_mode" = "true" ]; then
- + $MDADM --assemble $mddev --readonly --config=$RAIDCONF $MDADM_HOMEHOST
- + else
- + $MDADM --assemble $mddev --config=$RAIDCONF $MDADM_HOMEHOST
- + fi
- + udev_settle --exit-if-exists=$mddev
- +
- }
- #
- # START: Start up the RAID device
- #
- raid1_start() {
- local rc
- + check_mdadm_version
- + rc=$?
- + if [ $rc -ne $OCF_SUCCESS ]; then
- + ocf_log err "Didn't pass the version check. Make sure you have the latest mdadm installed!"
- + return $OCF_ERR_GENERIC
- + fi
- raid1_monitor
- rc=$?
- if [ $rc -eq $OCF_SUCCESS ]; then
- @@ -268,7 +486,7 @@
- get_users_pids() {
- local mddev=$1
- local outp l
- - ocf_log debug "running lsof to list $mddev users..."
- + ocf_log info "running lsof to list $mddev users..."
- outp=`lsof $mddev | tail -n +2`
- echo "$outp" | awk '{print $2}' | sort -u
- echo "$outp" | while read l; do
- @@ -406,7 +624,9 @@
- ocf_log err "$mddev: I/O error on read"
- return $OCF_ERR_GENERIC
- fi
- -
- + if [ "$OCF_RESKEY_master_slave_mode" = "true" -a `get_raid1_state $MDDEV` != readonly ]; then
- + return $OCF_RUNNING_MASTER
- + fi
- return $OCF_SUCCESS
- }
- @@ -460,6 +680,7 @@
- MDDEV="$OCF_RESKEY_raiddev"
- FORCESTOP="${OCF_RESKEY_force_stop:-1}"
- WAIT_FOR_UDEV="${OCF_RESKEY_udev:-1}"
- +PREFERRED_MASTER="$OCF_RESKEY_preferred_master"
- if [ -z "$RAIDCONF" ] ; then
- ocf_log err "Please set OCF_RESKEY_raidconf!"
- @@ -544,6 +765,15 @@
- monitor)
- raid1_monitor
- ;;
- + promote)
- + raid1_promote
- + ;;
- + demote)
- + raid1_demote
- + ;;
- + notify)
- + raid1_notify
- + ;;
- validate-all)
- raid1_validate_all
- ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement