summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-07-28 15:53:12 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-07-28 15:53:12 +0100
commit9df18b1f7ba7345d816a7c47df3f5e54dd98ba7b (patch)
tree2ee01081052a81f8bbe71ed704860fdad1ab5dfd
parentf61f1d476637c087a81509cd2c5bdf1ecfc59ba6 (diff)
parent2856bc945e742d531e3fb79025efe4c79610bf5e (diff)
downloadrabbitmq-server-git-9df18b1f7ba7345d816a7c47df3f5e54dd98ba7b.tar.gz
Merge bug26242
-rw-r--r--src/rabbit_control_main.erl27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index b8b6afad8a..e428d31405 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -115,6 +115,11 @@
{"Policies", rabbit_policy, list_formatted, info_keys},
{"Parameters", rabbit_runtime_parameters, list_formatted, info_keys}]).
+-define(COMMANDS_NOT_REQUIRING_APP,
+ [stop, stop_app, start_app, wait, reset, force_reset, rotate_logs,
+ join_cluster, change_cluster_node_type, update_cluster_nodes,
+ forget_cluster_node, cluster_status, status, environment, eval]).
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
@@ -156,7 +161,7 @@ start() ->
%% The reason we don't use a try/catch here is that rpc:call turns
%% thrown errors into normal return values
- case catch action(Command, Node, Args, Opts, Inform) of
+ case catch do_action(Command, Node, Args, Opts, Inform) of
ok ->
case Quiet of
true -> ok;
@@ -251,6 +256,15 @@ parse_arguments(CmdLine, NodeStr) ->
%%----------------------------------------------------------------------------
+do_action(Command, Node, Args, Opts, Inform) ->
+ case lists:member(Command, ?COMMANDS_NOT_REQUIRING_APP) of
+ false -> case ensure_app_running(Node) of
+ ok -> action(Command, Node, Args, Opts, Inform);
+ E -> E
+ end;
+ true -> action(Command, Node, Args, Opts, Inform)
+ end.
+
action(stop, Node, Args, _Opts, Inform) ->
Inform("Stopping and halting node ~p", [Node]),
Res = call(Node, {rabbit, stop_and_halt, []}),
@@ -744,6 +758,17 @@ unsafe_rpc(Node, Mod, Fun, Args) ->
Normal -> Normal
end.
+ensure_app_running(Node) ->
+ case call(Node, {rabbit, is_running, []}) of
+ true -> ok;
+ false -> {error_string,
+ rabbit_misc:format(
+ "rabbit application is not running on node ~s.~n"
+ " * Suggestion: start it with \"rabbitmqctl start_app\" "
+ "and try again", [Node])};
+ Other -> Other
+ end.
+
call(Node, {Mod, Fun, Args}) ->
rpc_call(Node, Mod, Fun, lists:map(fun list_to_binary_utf8/1, Args)).