diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2011-01-26 16:12:13 +0000 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2011-01-26 16:12:13 +0000 |
| commit | 306afd02529066aeb470a118f106d14dce441742 (patch) | |
| tree | fa32bd7e589ea9eb277f791ab619a1aaa896f172 /src | |
| parent | 8b22b74269c19286a6c2988f58c66696e3930f69 (diff) | |
| download | rabbitmq-server-git-306afd02529066aeb470a118f106d14dce441742.tar.gz | |
rabbitmqctl status is not adequate to wait for the server as it can return
successfully when the vm has started but not the app. The app can then fail.
Therefore introduce a new command to wait for the app to start.
Note that this subcommand contains a timeout to wait for the VM to
start, but will wait indefinitely for the app to start once the VM
has.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_control.erl | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 8048309714..a7d07b0f38 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -20,6 +20,7 @@ -export([start/0, stop/0, action/5, diagnostics/1]). -define(RPC_TIMEOUT, infinity). +-define(WAIT_FOR_VM_TIMEOUT, 5000). -define(QUIET_OPT, "-q"). -define(NODE_OPT, "-n"). @@ -297,7 +298,30 @@ action(list_permissions, Node, [], Opts, Inform) -> VHost = proplists:get_value(?VHOST_OPT, Opts), Inform("Listing permissions in vhost ~p", [VHost]), display_list(call(Node, {rabbit_auth_backend_internal, - list_vhost_permissions, [VHost]})). + list_vhost_permissions, [VHost]})); + +action(wait, Node, [], _Opts, Inform) -> + Inform("Waiting for ~p", [Node]), + wait_for_application(Node, ?WAIT_FOR_VM_TIMEOUT). + +wait_for_application(_Node, NodeTimeout) when NodeTimeout =< 0 -> + {badrpc, nodedown}; + +wait_for_application(Node, NodeTimeout) -> + case call(Node, {application, which_applications, []}) of + {badrpc, nodedown} -> wait_for_application0(Node, NodeTimeout - 1000); + {badrpc, _} = E -> E; + Apps -> case proplists:is_defined(rabbit, Apps) of + %% We've seen the node up; if it goes down + %% die immediately. + false -> wait_for_application0(Node, 0); + true -> ok + end + end. + +wait_for_application0(Node, NodeTimeout) -> + timer:sleep(1000), + wait_for_application(Node, NodeTimeout). default_if_empty(List, Default) when is_list(List) -> if List == [] -> |
