Skip to content

Commit 614ccfc

Browse files
author
Matthias Radestock
committed
two bug fixes and some refactoring
- the IP address in the config is meant to be a string, not an atom - special case node name of first node
1 parent f7d8d43 commit 614ccfc

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/rabbit_multi.erl

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ Available commands:
100100
action(start_all, [NodeCount], RpcTimeout) ->
101101
io:format("Starting all nodes...~n", []),
102102
application:load(rabbit),
103-
N = list_to_integer(NodeCount),
103+
NodeName = rabbit_misc:nodeparts(getenv("RABBITMQ_NODENAME")),
104104
{NodePids, Running} =
105-
start_nodes(N, N, [], true,
106-
rabbit_misc:nodeparts(
107-
getenv("RABBITMQ_NODENAME")),
108-
get_node_tcp_listener(1 == N),
109-
RpcTimeout),
105+
case list_to_integer(NodeCount) of
106+
1 -> {NodePid, Started} = start_node(rabbit_misc:makenode(NodeName),
107+
RpcTimeout),
108+
{[NodePid], Started};
109+
N -> start_nodes(N, N, [], true, NodeName,
110+
get_node_tcp_listener(), RpcTimeout)
111+
end,
110112
write_pids_file(NodePids),
111113
case Running of
112114
true -> ok;
@@ -159,30 +161,26 @@ action(rotate_logs, [Suffix], RpcTimeout) ->
159161
%% Running is a boolean exhibiting success at some moment
160162
start_nodes(0, _, PNodePid, Running, _, _, _) -> {PNodePid, Running};
161163

162-
start_nodes(1, 1, [], true, NodeName, NodeListen, RpcTimeout) ->
163-
{NodePid, Started} = start_single_node(rabbit_misc:makenode(NodeName),
164-
RpcTimeout),
165-
start_nodes(0, 1, [NodePid], Started, NodeName, NodeListen, RpcTimeout);
166-
167164
start_nodes(N, Total, PNodePid, Running,
168165
NodeNameBase, {NodeIpAddress, NodePortBase}, RpcTimeout) ->
169166
{NodePre, NodeSuff} = NodeNameBase,
170167
NodeNumber = Total - N,
171-
NodePre1 = NodePre ++ "_" ++ integer_to_list(NodeNumber),
172-
{NodePid, Started} = start_node(rabbit_misc:makenode({NodePre1, NodeSuff}),
173-
{NodeIpAddress, NodePortBase + NodeNumber},
174-
RpcTimeout),
168+
NodePre1 = case NodeNumber of
169+
%% For compatibility with running a single node
170+
0 -> NodePre;
171+
_ -> NodePre ++ "_" ++ integer_to_list(NodeNumber)
172+
end,
173+
Node = rabbit_misc:makenode({NodePre1, NodeSuff}),
174+
NodePort = NodePortBase + NodeNumber,
175+
os:putenv("RABBITMQ_NODENAME", atom_to_list(Node)),
176+
os:putenv("RABBITMQ_NODE_PORT", integer_to_list(NodePort)),
177+
os:putenv("RABBITMQ_NODE_IP_ADDRESS", NodeIpAddress),
178+
{NodePid, Started} = start_node(Node, RpcTimeout),
175179
start_nodes(N - 1, Total, [NodePid | PNodePid],
176180
Started and Running, NodeNameBase,
177181
{NodeIpAddress, NodePortBase}, RpcTimeout).
178182

179-
start_node(Node, {NodeIpAddress, NodePort}, RpcTimeout) ->
180-
os:putenv("RABBITMQ_NODENAME", atom_to_list(Node)),
181-
os:putenv("RABBITMQ_NODE_PORT", integer_to_list(NodePort)),
182-
os:putenv("RABBITMQ_NODE_IP_ADDRESS", atom_to_list(NodeIpAddress)),
183-
start_single_node(Node, RpcTimeout).
184-
185-
start_single_node(Node, RpcTimeout) ->
183+
start_node(Node, RpcTimeout) ->
186184
io:format("Starting node ~s...~n", [Node]),
187185
case rpc:call(Node, os, getpid, []) of
188186
{badrpc, _} ->
@@ -298,7 +296,7 @@ kill_wait(Pid, TimeLeft, Forceful) ->
298296
io:format(".", []),
299297
is_dead(Pid) orelse kill_wait(Pid, TimeLeft - ?RPC_SLEEP, Forceful).
300298

301-
% Test using some OS clunkiness since we shouldn't trust
299+
% Test using some OS clunkiness since we shouldn't trust
302300
% rpc:call(os, getpid, []) at this point
303301
is_dead(Pid) ->
304302
PidS = integer_to_list(Pid),
@@ -327,16 +325,14 @@ getenv(Var) ->
327325
Value -> Value
328326
end.
329327

330-
get_node_tcp_listener(OneNode) ->
328+
get_node_tcp_listener() ->
331329
try
332-
{list_to_atom(getenv("RABBITMQ_NODE_IP_ADDRESS")),
330+
{getenv("RABBITMQ_NODE_IP_ADDRESS"),
333331
list_to_integer(getenv("RABBITMQ_NODE_PORT"))}
334332
catch _ ->
335333
case application:get_env(rabbit, tcp_listeners) of
336334
{ok, [{_IpAddy, _Port} = Listener]} ->
337335
Listener;
338-
{ok, _Other} when OneNode ->
339-
it_matters_not;
340336
{ok, Other} ->
341337
throw({cannot_start_multiple_nodes, multiple_tcp_listeners,
342338
Other});

0 commit comments

Comments
 (0)