--- /dev/null
+diff -ru rabbitmq-server.orig/scripts/rabbitmq-server-ha.ocf rabbitmq-server/scripts/rabbitmq-server-ha.ocf
+--- rabbitmq-server.orig/scripts/rabbitmq-server-ha.ocf 2016-05-25 14:23:06.040484421 +0300
++++ rabbitmq-server/scripts/rabbitmq-server-ha.ocf 2016-06-07 16:40:37.544291736 +0300
+@@ -13,8 +13,8 @@
+ #
+ # See usage() function below for more details ...
+ #
+-# Note that the script uses set_rabbitmq_policy.sh script located in the
+-# same directory to setup RabbitMQ policies.
++# Note that the script uses an external file to setup RabbitMQ policies
++# so make sure to create it from an example shipped with the package.
+ #
+ #######################################################################
+ # Initialization:
+@@ -46,6 +46,7 @@
+ OCF_RESKEY_use_fqdn_default=false
+ OCF_RESKEY_fqdn_prefix_default=""
+ OCF_RESKEY_max_rabbitmqctl_timeouts_default=3
++OCF_RESKEY_policy_file_default="/usr/local/sbin/set_rabbitmq_policy"
+
+ : ${HA_LOGTAG="lrmd"}
+ : ${HA_LOGFACILITY="daemon"}
+@@ -66,6 +67,7 @@
+ : ${OCF_RESKEY_use_fqdn=${OCF_RESKEY_use_fqdn_default}}
+ : ${OCF_RESKEY_fqdn_prefix=${OCF_RESKEY_fqdn_prefix_default}}
+ : ${OCF_RESKEY_max_rabbitmqctl_timeouts=${OCF_RESKEY_max_rabbitmqctl_timeouts_default}}
++: ${OCF_RESKEY_policy_file=${OCF_RESKEY_policy_file_default}}
+
+ #######################################################################
+
+@@ -288,6 +290,14 @@
+ <content type="string" default="${OCF_RESKEY_max_rabbitmqctl_timeouts_default}" />
+ </parameter>
+
++<parameter name="policy_file" unique="0" required="0">
++<longdesc lang="en">
++A path to the shell script to setup RabbitMQ policies
++</longdesc>
++<shortdesc lang="en">A policy file path</shortdesc>
++<content type="string" default="${OCF_RESKEY_policy_file_default}" />
++</parameter>
++
+ $EXTENDED_OCF_PARAMS
+
+ </parameters>
+@@ -613,7 +623,7 @@
+ fi
+ done
+
+- export LL="${OCF_RESOURCE_INSTANCE}:"
++ export LL="${OCF_RESOURCE_INSTANCE}[$$]:"
+ update_cookie
+ }
+
+@@ -668,8 +678,8 @@
+ # remove mnesia files, if required
+ if $make_amnesia ; then
+ kill_rmq_and_remove_pid
+- ocf_run rm -rf "${MNESIA_FILES}/*"
+- ocf_log warn "${LH} Mnesia files appear corrupted and have been removed."
++ ocf_run rm -rf "${MNESIA_FILES}"
++ ocf_log warn "${LH} Mnesia files appear corrupted and have been removed from ${MNESIA_FILES}."
+ fi
+ # always return OCF SUCCESS
+ return $OCF_SUCCESS
+@@ -1286,6 +1296,7 @@
+ get_status() {
+ local what="${1:-kernel}"
+ local rc=$OCF_NOT_RUNNING
++ local LH="${LL} get_status():"
+ local body
+ local beam_running
+
+@@ -1296,11 +1307,11 @@
+ beam_running=$?
+ # report not running only if the which_applications() reported an error AND the beam is not running
+ if [ $rc -ne 0 -a $beam_running -ne 0 ] ; then
+- ocf_log info "get_status() failed with code ${rc}. Command output: ${body}"
++ ocf_log info "${LH} failed with code ${rc}. Command output: ${body}"
+ return $OCF_NOT_RUNNING
+ # return a generic error, if there were errors and beam is found running
+ elif [ $rc -ne 0 ] ; then
+- ocf_log info "get_status() found the beam process running but failed with code ${rc}. Command output: ${body}"
++ ocf_log info "${LH} found the beam process running but failed with code ${rc}. Command output: ${body}"
+ return $OCF_ERR_GENERIC
+ fi
+
+@@ -1310,7 +1321,7 @@
+ echo "$body" | grep "\{${what}," 2>&1 > /dev/null && rc=$OCF_SUCCESS
+
+ if [ $rc -ne $OCF_SUCCESS ] ; then
+- ocf_log info "get_status(): app ${what} was not found in command output: ${body}"
++ ocf_log info "${LH} app ${what} was not found in command output: ${body}"
+ fi
+ fi
+
+@@ -1452,6 +1463,7 @@
+ # Rabbit is running but is not connected to master
+ # Failing to avoid split brain
+ ocf_log err "${LH} rabbit node is running out of the cluster"
++ stop_server_process
+ rc=$OCF_ERR_GENERIC
+ fi
+ fi
+@@ -1468,6 +1480,7 @@
+
+ if [ -n "$master_name" ]; then
+ ocf_log info "${LH} master exists and rabbit app is not running. Exiting to be restarted by pacemaker"
++ stop_server_process
+ rc=$OCF_ERR_GENERIC
+ fi
+ fi
+@@ -1578,6 +1591,10 @@
+ fi
+ fi
+
++ if ! is-cluster-status-ok ; then
++ rc=$OCF_ERR_GENERIC
++ fi
++
+ # Check if the list of all queues is available,
+ # Also report some queues stats and total virtual memory.
+ local queues
+@@ -1617,6 +1634,36 @@
+ return $rc
+ }
+
++ocf-update-private-attr() {
++ local attr_name="${1:?}"
++ local attr_value="${2:?}"
++ ocf_run attrd_updater -p --name "$attr_name" --update "$attr_value"
++}
++
++rabbitmqctl-with-timeout-check() {
++ local command="${1:?}"
++ local timeout_attr_name="${2:?}"
++
++ su_rabbit_cmd "${OCF_RESKEY_ctl} $command"
++ local rc=$?
++
++ check_timeouts $rc $timeout_attr_name "$command"
++ local has_timed_out=$?
++
++ case "$has_timed_out" in
++ 0)
++ return $rc;;
++ 1)
++ return 0;;
++ 2)
++ return 1;;
++ esac
++}
++
++is-cluster-status-ok() {
++ local LH="${LH}: is-cluster-status-ok:"
++ rabbitmqctl-with-timeout-check cluster_status rabbit_cluster_status_timeouts > /dev/null 2>&1
++}
+
+ action_monitor() {
+ local rc=$OCF_ERR_GENERIC
+@@ -1657,9 +1704,12 @@
+ return $OCF_SUCCESS
+ fi
+
+- ocf_run attrd_updater -p --name 'rabbit_list_channels_timeouts' --update '0'
+- ocf_run attrd_updater -p --name 'rabbit_get_alarms_timeouts' --update '0'
+- ocf_run attrd_updater -p --name 'rabbit_list_queues_timeouts' --update '0'
++ local attrs_to_zero="rabbit_list_channels_timeouts rabbit_get_alarms_timeouts rabbit_list_queues_timeouts rabbit_cluster_status_timeouts"
++ local attr_name_to_reset
++ for attr_name_to_reset in $attrs_to_zero; do
++ ocf-update-private-attr $attr_name_to_reset 0
++ done
++
+ ocf_log info "${LH} Deleting start time attribute"
+ ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --delete
+ ocf_log info "${LH} Deleting master attribute"
+@@ -2097,8 +2147,7 @@
+ exit $OCF_FAILED_MASTER
+ fi
+
+- local set_policy_path="$(dirname $0)/set_rabbitmq_policy.sh"
+- [ -f $set_policy_path ] && . $set_policy_path
++ [ -f "${OCF_RESKEY_policy_file}" ] && . "${OCF_RESKEY_policy_file}"
+
+ # create timestamp file
+ nowtime="$(now)"