summaryrefslogtreecommitdiff
path: root/src/rabbit_multi.erl
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2010-09-10 17:12:41 +0100
committerMatthew Sackman <matthew@rabbitmq.com>2010-09-10 17:12:41 +0100
commit2c3a7a80dd38c07c190164546f29fbf2d5dc0400 (patch)
tree64ec18e366ba2ada8a56058377f7a5f41efd21ee /src/rabbit_multi.erl
parent1a1acaa30a629312da86503de4a40c278b47bbc8 (diff)
parent432aefa0b24e199ec5b694da32187b777348cf61 (diff)
downloadrabbitmq-server-2c3a7a80dd38c07c190164546f29fbf2d5dc0400.tar.gz
Merging default into bug 23157
Diffstat (limited to 'src/rabbit_multi.erl')
-rw-r--r--src/rabbit_multi.erl23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl
index 3facef17..5cfd6a5c 100644
--- a/src/rabbit_multi.erl
+++ b/src/rabbit_multi.erl
@@ -93,7 +93,14 @@ usage() ->
action(start_all, [NodeCount], RpcTimeout) ->
io:format("Starting all nodes...~n", []),
application:load(rabbit),
- NodeName = rabbit_misc:nodeparts(getenv("RABBITMQ_NODENAME")),
+ {_NodeNamePrefix, NodeHost} = NodeName = rabbit_misc:nodeparts(
+ getenv("RABBITMQ_NODENAME")),
+ case net_adm:names(NodeHost) of
+ {error, EpmdReason} ->
+ throw({cannot_connect_to_epmd, NodeHost, EpmdReason});
+ {ok, _} ->
+ ok
+ end,
{NodePids, Running} =
case list_to_integer(NodeCount) of
1 -> {NodePid, Started} = start_node(rabbit_misc:makenode(NodeName),
@@ -303,8 +310,8 @@ kill_wait(Pid, TimeLeft, Forceful) ->
is_dead(Pid) ->
PidS = integer_to_list(Pid),
with_os([{unix, fun () ->
- Res = os:cmd("ps --no-headers --pid " ++ PidS),
- Res == ""
+ system("kill -0 " ++ PidS
+ ++ " >/dev/null 2>&1") /= 0
end},
{win32, fun () ->
Res = os:cmd("tasklist /nh /fi \"pid eq " ++
@@ -315,6 +322,16 @@ is_dead(Pid) ->
end
end}]).
+% Like system(3)
+system(Cmd) ->
+ ShCmd = "sh -c '" ++ escape_quotes(Cmd) ++ "'",
+ Port = erlang:open_port({spawn, ShCmd}, [exit_status,nouse_stdio]),
+ receive {Port, {exit_status, Status}} -> Status end.
+
+% Escape the quotes in a shell command so that it can be used in "sh -c 'cmd'"
+escape_quotes(Cmd) ->
+ lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)).
+
call_all_nodes(Func) ->
case read_pids_file() of
[] -> throw(no_nodes_running);