Blame SOURCES/bz1303803-Backup-and-restore-rabbitmq-users-during-resource-re.patch

f784e8
From: Peter Lemenkov <lemenkov@redhat.com>
f784e8
Date: Mon, 29 Feb 2016 12:46:50 +0100
f784e8
Subject: [PATCH] Backup and restore rabbitmq users during resource restart
f784e8
f784e8
Signed-off-by: Peter Lemenkov <lemenkov@redhat.com>
f784e8
f784e8
diff --git a/heartbeat/rabbitmq-cluster b/heartbeat/rabbitmq-cluster
f784e8
index cc45f09..4545495 100755
f784e8
--- a/heartbeat/rabbitmq-cluster
f784e8
+++ b/heartbeat/rabbitmq-cluster
f784e8
@@ -289,7 +289,19 @@ rmq_start() {
f784e8
 		rmq_stop 
f784e8
 		rmq_wipe_data
f784e8
 		rmq_join_existing "$join_list"
f784e8
-		if [ $? -ne 0 ]; then
f784e8
+		rc=$?
f784e8
+
f784e8
+                # Restore users (if any)
f784e8
+                BaseDataDir=`dirname $RMQ_DATA_DIR`
f784e8
+                if [ -f $BaseDataDir/users.erl ] ; then
f784e8
+                        rabbitmqctl eval "
f784e8
+                                {ok, [Users]} = file:consult(\"$BaseDataDir/users.erl\"),
f784e8
+                                lists:foreach(fun(X) -> mnesia:dirty_write(rabbit_user, X) end, Users).
f784e8
+                        "
f784e8
+                        rm -f $BaseDataDir/users.erl
f784e8
+                fi
f784e8
+
f784e8
+		if [ $rc -ne 0 ]; then
f784e8
 			ocf_log info "node failed to join even after reseting local data. Check SELINUX policy"
f784e8
 			return $OCF_ERR_GENERIC
f784e8
 		fi
f784e8
@@ -299,6 +311,13 @@ rmq_start() {
f784e8
 }
f784e8
 
f784e8
 rmq_stop() {
f784e8
+        # Backup users
f784e8
+        BaseDataDir=`dirname $RMQ_DATA_DIR`
f784e8
+        rabbitmqctl eval "
f784e8
+                Users = mnesia:dirty_select(rabbit_user, [{ {internal_user, '\\\$1', '_', '_'}, [{'/=', '\\\$1', <<\"guest\">>}], ['\\\$_'] } ]),
f784e8
+                file:write_file(\"$BaseDataDir/users.erl\", io_lib:fwrite(\"~p.~n\", [Users])).
f784e8
+        "
f784e8
+
f784e8
 	rmq_monitor
f784e8
 	if [ $? -eq $OCF_NOT_RUNNING ]; then
f784e8
 		return $OCF_SUCCESS