|
|
be1049 |
diff -uNr a/heartbeat/rabbitmq-cluster b/heartbeat/rabbitmq-cluster
|
|
|
be1049 |
--- a/heartbeat/rabbitmq-cluster 2017-01-20 15:37:43.698833068 +0100
|
|
|
be1049 |
+++ b/heartbeat/rabbitmq-cluster 2017-01-20 16:28:56.170739557 +0100
|
|
|
be1049 |
@@ -1,6 +1,6 @@
|
|
|
be1049 |
#!/bin/sh
|
|
|
be1049 |
#
|
|
|
be1049 |
-# Copyright (c) 2014 David Vossel <dvossel@redhat.com>
|
|
|
be1049 |
+# Copyright (c) 2014 David Vossel <davidvossel@gmail.com>
|
|
|
be1049 |
# All Rights Reserved.
|
|
|
be1049 |
#
|
|
|
be1049 |
# This program is free software; you can redistribute it and/or modify
|
|
|
be1049 |
@@ -52,7 +52,7 @@
|
|
|
be1049 |
cat <
|
|
|
be1049 |
|
|
|
be1049 |
|
|
|
be1049 |
-<resource-agent name="rabbitmq-cluster" version="0.9">
|
|
|
be1049 |
+<resource-agent name="rabbitmq-cluster">
|
|
|
be1049 |
<version>1.0</version>
|
|
|
be1049 |
|
|
|
be1049 |
<longdesc lang="en">
|
|
|
be1049 |
@@ -111,7 +111,7 @@
|
|
|
be1049 |
|
|
|
be1049 |
rmq_join_list()
|
|
|
be1049 |
{
|
|
|
be1049 |
- cibadmin -Q 2>/dev/null | grep "$RMQ_CRM_ATTR_COOKIE" | sed -n -e "s/^.*value=.\(.*\)\".*$/\1/p"
|
|
|
be1049 |
+ cibadmin -Q --xpath "//node_state[@crmd='online']//nvpair[@name='$RMQ_CRM_ATTR_COOKIE']" | grep "$RMQ_CRM_ATTR_COOKIE" | sed -n -e "s/^.*value=.\(.*\)\".*$/\1/p"
|
|
|
be1049 |
}
|
|
|
be1049 |
|
|
|
be1049 |
rmq_write_nodename()
|
|
|
be1049 |
@@ -203,7 +203,7 @@
|
|
|
be1049 |
|
|
|
be1049 |
rmq_set_policy()
|
|
|
be1049 |
{
|
|
|
be1049 |
- $RMQ_CTL set_policy $@ > /dev/null 2>&1
|
|
|
be1049 |
+ $RMQ_CTL set_policy "$@" > /dev/null 2>&1
|
|
|
be1049 |
}
|
|
|
be1049 |
|
|
|
be1049 |
rmq_start_first()
|
|
|
be1049 |
@@ -284,7 +284,6 @@
|
|
|
be1049 |
return $OCF_SUCCESS
|
|
|
be1049 |
}
|
|
|
be1049 |
|
|
|
be1049 |
-
|
|
|
be1049 |
rmq_forget_cluster_node_remotely() {
|
|
|
be1049 |
local running_cluster_nodes="$1"
|
|
|
be1049 |
local node_to_forget="$2"
|
|
|
be1049 |
@@ -354,26 +353,28 @@
|
|
|
be1049 |
return $rc
|
|
|
be1049 |
fi
|
|
|
be1049 |
|
|
|
be1049 |
- # first try to join without wiping mnesia data
|
|
|
be1049 |
- rmq_join_existing "$join_list"
|
|
|
be1049 |
- if [ $? -ne 0 ]; then
|
|
|
be1049 |
- ocf_log info "node failed to join, wiping data directory and trying again"
|
|
|
be1049 |
- local local_rmq_node="$(${HA_SBIN_DIR}/crm_attribute -N $NODENAME -l forever --query --name $RMQ_CRM_ATTR_COOKIE_LAST_KNOWN -q)"
|
|
|
be1049 |
+ # Try to join existing cluster
|
|
|
be1049 |
+ ocf_log info "wiping data directory before joining"
|
|
|
be1049 |
+ local local_rmq_node="$(${HA_SBIN_DIR}/crm_attribute -N $NODENAME -l forever --query --name $RMQ_CRM_ATTR_COOKIE_LAST_KNOWN -q)"
|
|
|
be1049 |
|
|
|
be1049 |
- # if the graceful join fails, use the hammer and reset all the data.
|
|
|
be1049 |
- rmq_stop
|
|
|
be1049 |
- rmq_wipe_data
|
|
|
be1049 |
- rmq_forget_cluster_node_remotely "$join_list" "$local_rmq_node"
|
|
|
be1049 |
- rmq_join_existing "$join_list"
|
|
|
be1049 |
- rc=$?
|
|
|
be1049 |
+ rmq_stop
|
|
|
be1049 |
+ rmq_wipe_data
|
|
|
be1049 |
+ rmq_forget_cluster_node_remotely "$join_list" "$local_rmq_node"
|
|
|
be1049 |
+ rmq_join_existing "$join_list"
|
|
|
be1049 |
+ rc=$?
|
|
|
be1049 |
|
|
|
be1049 |
- # Restore users (if any)
|
|
|
be1049 |
- BaseDataDir=`dirname $RMQ_DATA_DIR`
|
|
|
be1049 |
- if [ -f $BaseDataDir/users.erl ] ; then
|
|
|
be1049 |
- rabbitmqctl eval "
|
|
|
be1049 |
- %% Run only if Mnesia is ready, otherwise exit.
|
|
|
be1049 |
- lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) orelse halt(),
|
|
|
be1049 |
+ if [ $rc -ne 0 ]; then
|
|
|
be1049 |
+ ocf_log info "node failed to join even after reseting local data. Check SELINUX policy"
|
|
|
be1049 |
+ return $OCF_ERR_GENERIC
|
|
|
be1049 |
+ fi
|
|
|
be1049 |
|
|
|
be1049 |
+ # Restore users and users' permissions (if any)
|
|
|
be1049 |
+ BaseDataDir=`dirname $RMQ_DATA_DIR`
|
|
|
be1049 |
+ if [ -f $BaseDataDir/users.erl ] ; then
|
|
|
be1049 |
+ rabbitmqctl eval "
|
|
|
be1049 |
+ %% Run only if Mnesia is ready.
|
|
|
be1049 |
+ lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) andalso
|
|
|
be1049 |
+ begin
|
|
|
be1049 |
[WildPattern] = ets:select(mnesia_gvar, [ { {{rabbit_user, wild_pattern}, '\\\$1'}, [], ['\\\$1'] } ]),
|
|
|
be1049 |
|
|
|
be1049 |
%% Read users first
|
|
|
be1049 |
@@ -400,39 +401,51 @@
|
|
|
be1049 |
%% Version >= 3.6.0
|
|
|
be1049 |
{internal_user,'_','_','_','_'} ->
|
|
|
be1049 |
lists:foreach(fun(X) -> mnesia:dirty_write(rabbit_user, Upgrade(X)) end, Users)
|
|
|
be1049 |
- end.
|
|
|
be1049 |
- "
|
|
|
be1049 |
- rm -f $BaseDataDir/users.erl
|
|
|
be1049 |
- fi
|
|
|
be1049 |
-
|
|
|
be1049 |
- if [ $rc -ne 0 ]; then
|
|
|
be1049 |
- ocf_log info "node failed to join even after reseting local data. Check SELINUX policy"
|
|
|
be1049 |
- return $OCF_ERR_GENERIC
|
|
|
be1049 |
- fi
|
|
|
be1049 |
+ end,
|
|
|
be1049 |
+
|
|
|
be1049 |
+ ok = file:delete(\"$BaseDataDir/users.erl\")
|
|
|
be1049 |
+ end.
|
|
|
be1049 |
+ "
|
|
|
be1049 |
+ fi
|
|
|
be1049 |
+ if [ -f $BaseDataDir/users_perms.erl ] ; then
|
|
|
be1049 |
+ rabbitmqctl eval "
|
|
|
be1049 |
+ %% Run only if Mnesia is ready.
|
|
|
be1049 |
+ lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) andalso
|
|
|
be1049 |
+ begin
|
|
|
be1049 |
+ {ok, [UsersPerms]} = file:consult(\"$BaseDataDir/users_perms.erl\"),
|
|
|
be1049 |
+ lists:foreach(fun(X) -> mnesia:dirty_write(rabbit_user_permission, X) end, UsersPerms),
|
|
|
be1049 |
+
|
|
|
be1049 |
+ ok = file:delete(\"$BaseDataDir/users_perms.erl\")
|
|
|
be1049 |
+ end.
|
|
|
be1049 |
+ "
|
|
|
be1049 |
fi
|
|
|
be1049 |
|
|
|
be1049 |
return $OCF_SUCCESS
|
|
|
be1049 |
}
|
|
|
be1049 |
|
|
|
be1049 |
rmq_stop() {
|
|
|
be1049 |
- # Backup users
|
|
|
be1049 |
+ # Backup users and users' permissions
|
|
|
be1049 |
BaseDataDir=`dirname $RMQ_DATA_DIR`
|
|
|
be1049 |
rabbitmqctl eval "
|
|
|
be1049 |
- %% Run only if Mnesia is still available, otherwise exit.
|
|
|
be1049 |
- lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) orelse halt(),
|
|
|
be1049 |
-
|
|
|
be1049 |
- [WildPattern] = ets:select(mnesia_gvar, [ { {{rabbit_user, wild_pattern}, '\\\$1'}, [], ['\\\$1'] } ]),
|
|
|
be1049 |
-
|
|
|
be1049 |
- Users = case WildPattern of
|
|
|
be1049 |
- %% Version < 3.6.0
|
|
|
be1049 |
- {internal_user,'_','_','_'} ->
|
|
|
be1049 |
- mnesia:dirty_select(rabbit_user, [{ {internal_user, '\\\$1', '_', '_'}, [{'/=', '\\\$1', <<\"guest\">>}], ['\\\$_'] } ]);
|
|
|
be1049 |
- %% Version >= 3.6.0
|
|
|
be1049 |
- {internal_user,'_','_','_','_'} ->
|
|
|
be1049 |
- mnesia:dirty_select(rabbit_user, [{ {internal_user, '\\\$1', '_', '_', '_'}, [{'/=', '\\\$1', <<\"guest\">>}], ['\\\$_'] } ])
|
|
|
be1049 |
- end,
|
|
|
be1049 |
-
|
|
|
be1049 |
- file:write_file(\"$BaseDataDir/users.erl\", io_lib:fwrite(\"~p.~n\", [Users])).
|
|
|
be1049 |
+ %% Run only if Mnesia is still available.
|
|
|
be1049 |
+ lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) andalso
|
|
|
be1049 |
+ begin
|
|
|
be1049 |
+ [WildPattern] = ets:select(mnesia_gvar, [ { {{rabbit_user, wild_pattern}, '\\\$1'}, [], ['\\\$1'] } ]),
|
|
|
be1049 |
+
|
|
|
be1049 |
+ Users = case WildPattern of
|
|
|
be1049 |
+ %% Version < 3.6.0
|
|
|
be1049 |
+ {internal_user,'_','_','_'} ->
|
|
|
be1049 |
+ mnesia:dirty_select(rabbit_user, [{ {internal_user, '\\\$1', '_', '_'}, [{'/=', '\\\$1', <<\"guest\">>}], ['\\\$_'] } ]);
|
|
|
be1049 |
+ %% Version >= 3.6.0
|
|
|
be1049 |
+ {internal_user,'_','_','_','_'} ->
|
|
|
be1049 |
+ mnesia:dirty_select(rabbit_user, [{ {internal_user, '\\\$1', '_', '_', '_'}, [{'/=', '\\\$1', <<\"guest\">>}], ['\\\$_'] } ])
|
|
|
be1049 |
+ end,
|
|
|
be1049 |
+
|
|
|
be1049 |
+ Users /= [] andalso file:write_file(\"$BaseDataDir/users.erl\", io_lib:fwrite(\"~p.~n\", [Users])),
|
|
|
be1049 |
+
|
|
|
be1049 |
+ UsersPerms = mnesia:dirty_select(rabbit_user_permission, [{{'\\\$1', {'\\\$2', '\\\$3','\\\$4'}, '\\\$5'}, [{'/=', '\\\$3', <<\"guest\">>}], ['\\\$_']}]),
|
|
|
be1049 |
+ UsersPerms /= [] andalso file:write_file(\"$BaseDataDir/users_perms.erl\", io_lib:fwrite(\"~p.~n\", [UsersPerms]))
|
|
|
be1049 |
+ end.
|
|
|
be1049 |
"
|
|
|
be1049 |
|
|
|
be1049 |
rmq_monitor
|