Skip to content

Commit d63d9c9

Browse files
author
Marek Majkowski
committed
Merged bug 21662 into default (debugging info badrpc).
2 parents bca6c53 + 7325eb5 commit d63d9c9

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/rabbit.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ app_location() ->
219219
{ok, Application} = application:get_application(),
220220
filename:absname(code:where_is_file(atom_to_list(Application) ++ ".app")).
221221

222+
home_dir() ->
223+
case init:get_argument(home) of
224+
{ok, [[Home]]} -> Home;
225+
Other -> Other
226+
end.
227+
222228
%---------------------------------------------------------------------------
223229

224230
print_banner() ->
@@ -243,6 +249,8 @@ print_banner() ->
243249
?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]),
244250
Settings = [{"node", node()},
245251
{"app descriptor", app_location()},
252+
{"home dir", home_dir()},
253+
{"cookie hash", rabbit_misc:cookie_hash()},
246254
{"log", log_location(kernel)},
247255
{"sasl log", log_location(sasl)},
248256
{"database dir", rabbit_mnesia:dir()}],

src/rabbit_control.erl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,38 @@ start() ->
8080
{error, Reason} ->
8181
error("~p", [Reason]),
8282
halt(2);
83+
{badrpc, Reason} ->
84+
error("unable to connect to node ~w: ~w", [Node, Reason]),
85+
print_badrpc_diagnostics(Node),
86+
halt(2);
8387
Other ->
8488
error("~p", [Other]),
8589
halt(2)
8690
end.
8791

88-
error(Format, Args) ->
89-
rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args).
92+
fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args).
93+
94+
error(Format, Args) -> fmt_stderr("Error: " ++ Format, Args).
95+
96+
print_badrpc_diagnostics(Node) ->
97+
fmt_stderr("diagnostics:", []),
98+
NodeHost = rabbit_misc:nodehost(Node),
99+
case net_adm:names(NodeHost) of
100+
{error, EpmdReason} ->
101+
fmt_stderr("- unable to connect to epmd on ~s: ~w",
102+
[NodeHost, EpmdReason]);
103+
{ok, NamePorts} ->
104+
fmt_stderr("- nodes and their ports on ~s: ~p",
105+
[NodeHost, [{list_to_atom(Name), Port} ||
106+
{Name, Port} <- NamePorts]])
107+
end,
108+
fmt_stderr("- current node: ~w", [node()]),
109+
case init:get_argument(home) of
110+
{ok, [[Home]]} -> fmt_stderr("- current node home dir: ~s", [Home]);
111+
Other -> fmt_stderr("- no current node home dir: ~p", [Other])
112+
end,
113+
fmt_stderr("- current node cookie hash: ~s", [rabbit_misc:cookie_hash()]),
114+
ok.
90115

91116
parse_args(["-n", NodeS | Args], Params) ->
92117
Node = case lists:member($@, NodeS) of

src/rabbit_misc.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
-export([with_user/2, with_vhost/2, with_user_and_vhost/3]).
4848
-export([execute_mnesia_transaction/1]).
4949
-export([ensure_ok/2]).
50-
-export([localnode/1, tcp_name/3]).
50+
-export([localnode/1, nodehost/1, cookie_hash/0, tcp_name/3]).
5151
-export([intersperse/2, upmap/2, map_in_order/2]).
5252
-export([table_foreach/2]).
5353
-export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]).
@@ -106,6 +106,8 @@
106106
-spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A).
107107
-spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok').
108108
-spec(localnode/1 :: (atom()) -> erlang_node()).
109+
-spec(nodehost/1 :: (erlang_node()) -> string()).
110+
-spec(cookie_hash/0 :: () -> string()).
109111
-spec(tcp_name/3 :: (atom(), ip_address(), ip_port()) -> atom()).
110112
-spec(intersperse/2 :: (A, [A]) -> [A]).
111113
-spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]).
@@ -307,11 +309,15 @@ ensure_ok(ok, _) -> ok;
307309
ensure_ok({error, Reason}, ErrorTag) -> throw({error, {ErrorTag, Reason}}).
308310

309311
localnode(Name) ->
312+
list_to_atom(lists:append([atom_to_list(Name), "@", nodehost(node())])).
313+
314+
nodehost(Node) ->
310315
%% This is horrible, but there doesn't seem to be a way to split a
311316
%% nodename into its constituent parts.
312-
list_to_atom(lists:append(atom_to_list(Name),
313-
lists:dropwhile(fun (E) -> E =/= $@ end,
314-
atom_to_list(node())))).
317+
tl(lists:dropwhile(fun (E) -> E =/= $@ end, atom_to_list(Node))).
318+
319+
cookie_hash() ->
320+
ssl_base64:encode(erlang:md5(atom_to_list(erlang:get_cookie()))).
315321

316322
tcp_name(Prefix, IPAddress, Port)
317323
when is_atom(Prefix) andalso is_number(Port) ->

0 commit comments

Comments
 (0)