Skip to content

Commit 23a3077

Browse files
author
Francesco Mazzoli
committed
Added wait_node script to wait for the node to be up.
1 parent 5d56d9f commit 23a3077

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ start-background-node: all
207207
-rm -f $(RABBITMQ_MNESIA_DIR).pid
208208
mkdir -p $(RABBITMQ_MNESIA_DIR)
209209
setsid sh -c "$(MAKE) run-background-node > $(RABBITMQ_MNESIA_DIR)/startup_log 2> $(RABBITMQ_MNESIA_DIR)/startup_err" &
210-
sleep 5
210+
./wait_node $(RABBITMQ_NODENAME) $(RABBITMQ_MNESIA_DIR).pid
211211

212212
start-rabbit-on-node: all
213213
echo "rabbit:start()." | $(ERL_CALL)

src/rabbit_misc.erl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@
211211
-spec(os_cmd/1 :: (string()) -> string()).
212212
-spec(gb_sets_difference/2 :: (gb_set(), gb_set()) -> gb_set()).
213213
-spec(is_running/2 :: (node(), atom()) -> boolean()).
214-
-spec(wait_for_application/3 :: (node(), pid(), atom())
214+
-spec(wait_for_application/3 :: (node(), string(), atom())
215215
-> ok | {error, process_not_running}).
216-
-spec(wait_for_process_death/1 :: (pid()) -> ok).
217-
-spec(read_pid_file/2 :: (file:name(), boolean()) -> pid() | no_return()).
216+
-spec(wait_for_process_death/1 :: (string()) -> ok).
217+
-spec(read_pid_file/2 :: (file:name(), boolean()) -> string() | no_return()).
218218

219219
-endif.
220220

@@ -1000,6 +1000,3 @@ system(Cmd) ->
10001000
% Escape the quotes in a shell command so that it can be used in "sh -c 'cmd'"
10011001
escape_quotes(Cmd) ->
10021002
lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)).
1003-
1004-
format_parse_error({_Line, Mod, Err}) ->
1005-
lists:flatten(Mod:format_error(Err)).

wait_node

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env escript
2+
%% -*- erlang -*-
3+
%%! -sname wait_node -pa ./ebin
4+
5+
main([NodeStr, PidFile]) ->
6+
case {code:load_file(rabbit_misc), code:load_file(rabbit_nodes)} of
7+
{{module, _}, {module, _}} ->
8+
ok;
9+
_ ->
10+
io:format("Compile with 'make' before running this script~n")
11+
end,
12+
Node = rabbit_nodes:make(NodeStr),
13+
Pid = rabbit_misc:read_pid_file(PidFile, true),
14+
io:format("pid is ~s~n", [Pid]),
15+
rabbit_misc:wait_for_application(Node, Pid, kernel);
16+
main(_) ->
17+
usage().
18+
19+
usage() ->
20+
io:format("Usage: ./wait_node node pidfile~n"),
21+
halt(1).

0 commit comments

Comments
 (0)