summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-10-23 12:55:48 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-10-23 12:55:48 +0100
commit3b5475471a491360d36bcac3da42c22aa5770ff9 (patch)
tree54a714aa2abe2343af6df90d440c8bcf5915318b
parente79d40bbbe91d61f23dffc44d5f73716822c363f (diff)
downloadrabbitmq-server-git-3b5475471a491360d36bcac3da42c22aa5770ff9.tar.gz
First pass at having ctl and plugins not start epmd. This can cause problems though if we are contacting a remote node, or removing a cluster node offline.
-rwxr-xr-xscripts/rabbitmq-plugins2
-rwxr-xr-xscripts/rabbitmq-plugins.bat10
-rwxr-xr-xscripts/rabbitmqctl4
-rwxr-xr-xscripts/rabbitmqctl.bat4
-rw-r--r--src/rabbit_cli.erl27
-rw-r--r--src/rabbit_control_main.erl13
6 files changed, 28 insertions, 32 deletions
diff --git a/scripts/rabbitmq-plugins b/scripts/rabbitmq-plugins
index 29c4b0c86a..22fec32f0a 100755
--- a/scripts/rabbitmq-plugins
+++ b/scripts/rabbitmq-plugins
@@ -19,11 +19,11 @@
# Non-empty defaults should be set in rabbitmq-env
. `dirname $0`/rabbitmq-env
+RABBITMQ_USE_LONGNAME=${RABBITMQ_USE_LONGNAME} \
exec ${ERL_DIR}erl \
-pa "${RABBITMQ_HOME}/ebin" \
-noinput \
-hidden \
- ${RABBITMQ_NAME_TYPE} rabbitmq-plugins$$ \
-boot "${CLEAN_BOOT_FILE}" \
-s rabbit_plugins_main \
-enabled_plugins_file "$RABBITMQ_ENABLED_PLUGINS_FILE" \
diff --git a/scripts/rabbitmq-plugins.bat b/scripts/rabbitmq-plugins.bat
index 1ed648b0bc..b27a8586b2 100755
--- a/scripts/rabbitmq-plugins.bat
+++ b/scripts/rabbitmq-plugins.bat
@@ -23,14 +23,6 @@ set TDP0=%~dp0
set STAR=%*
setlocal enabledelayedexpansion
-if "!RABBITMQ_USE_LONGNAME!"=="" (
- set RABBITMQ_NAME_TYPE="-sname"
-)
-
-if "!RABBITMQ_USE_LONGNAME!"=="true" (
- set RABBITMQ_NAME_TYPE="-name"
-)
-
if "!RABBITMQ_SERVICENAME!"=="" (
set RABBITMQ_SERVICENAME=RabbitMQ
)
@@ -63,7 +55,7 @@ if "!RABBITMQ_PLUGINS_DIR!"=="" (
set RABBITMQ_PLUGINS_DIR=!TDP0!..\plugins
)
-"!ERLANG_HOME!\bin\erl.exe" -pa "!TDP0!..\ebin" -noinput -hidden !RABBITMQ_NAME_TYPE! rabbitmq-plugins!RANDOM!!TIME:~9! -s rabbit_plugins_main -enabled_plugins_file "!RABBITMQ_ENABLED_PLUGINS_FILE!" -plugins_dist_dir "!RABBITMQ_PLUGINS_DIR:\=/!" -nodename !RABBITMQ_NODENAME! -extra !STAR!
+"!ERLANG_HOME!\bin\erl.exe" -pa "!TDP0!..\ebin" -noinput -hidden -s rabbit_plugins_main -enabled_plugins_file "!RABBITMQ_ENABLED_PLUGINS_FILE!" -plugins_dist_dir "!RABBITMQ_PLUGINS_DIR:\=/!" -nodename !RABBITMQ_NODENAME! -extra !STAR!
endlocal
endlocal
diff --git a/scripts/rabbitmqctl b/scripts/rabbitmqctl
index 804c0c81f5..2237275c47 100755
--- a/scripts/rabbitmqctl
+++ b/scripts/rabbitmqctl
@@ -19,10 +19,6 @@
# Non-empty defaults should be set in rabbitmq-env
. `dirname $0`/rabbitmq-env
-# rabbitmqctl starts distribution itself, so we need to make sure epmd
-# is running.
-${ERL_DIR}erl ${RABBITMQ_NAME_TYPE} rabbitmqctl-prelaunch-$$ -noinput -eval 'erlang:halt().'
-
# We specify Mnesia dir and sasl error logger since some actions
# (e.g. forget_cluster_node --offline) require us to impersonate the
# real node.
diff --git a/scripts/rabbitmqctl.bat b/scripts/rabbitmqctl.bat
index 6eb2530a4e..e4d4745c16 100755
--- a/scripts/rabbitmqctl.bat
+++ b/scripts/rabbitmqctl.bat
@@ -63,10 +63,6 @@ if not exist "!ERLANG_HOME!\bin\erl.exe" (
exit /B
)
-rem rabbitmqctl starts distribution itself, so we need to make sure epmd
-rem is running.
-"!ERLANG_HOME!\bin\erl.exe" !RABBITMQ_NAME_TYPE! rabbitmqctl-prelaunch-!RANDOM!!TIME:~9! -noinput -eval "erlang:halt()."
-
"!ERLANG_HOME!\bin\erl.exe" ^
-pa "!TDP0!..\ebin" ^
-noinput ^
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl
index 2981f3b2ce..a946c12a16 100644
--- a/src/rabbit_cli.erl
+++ b/src/rabbit_cli.erl
@@ -17,7 +17,7 @@
-module(rabbit_cli).
-include("rabbit_cli.hrl").
--export([main/3, parse_arguments/4]).
+-export([main/3, name_type/0, parse_arguments/4]).
%%----------------------------------------------------------------------------
@@ -31,6 +31,7 @@
-spec(main/3 :: (fun (([string()], string()) -> parse_result()),
fun ((atom(), atom(), [any()], [any()]) -> any()),
atom()) -> no_return()).
+-spec(name_type/0 :: () -> 'shortnames' | 'longnames').
-spec(usage/1 :: (atom()) -> no_return()).
-spec(parse_arguments/4 ::
([{atom(), [{string(), optdef()}]} | atom()],
@@ -57,7 +58,10 @@ main(ParseFun, DoFun, UsageMod) ->
%% The reason we don't use a try/catch here is that rpc:call turns
%% thrown errors into normal return values
- case catch DoFun(Command, Node, Args, Opts) of
+ case catch begin
+ start_distribution(),
+ DoFun(Command, Node, Args, Opts)
+ end of
ok ->
rabbit_misc:quit(0);
{'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> %% < R15
@@ -73,6 +77,12 @@ main(ParseFun, DoFun, UsageMod) ->
{'EXIT', {badarg, _}} ->
print_error("invalid parameter: ~p", [Args]),
usage(UsageMod);
+ {error, {distribution_failed, _}} ->
+ print_error(
+ "Could not start distribution.~n"
+ "The most likely reason is that epmd has not been started by~n"
+ "the server. Make sure the server is running.~n", []),
+ rabbit_misc:quit(2);
{error, {Problem, Reason}} when is_atom(Problem), is_binary(Reason) ->
%% We handle this common case specially to avoid ~p since
%% that has i18n issues
@@ -100,6 +110,19 @@ main(ParseFun, DoFun, UsageMod) ->
rabbit_misc:quit(2)
end.
+start_distribution() ->
+ CtlNodeName = rabbit_misc:format("rabbitmq-cli-~s", [os:getpid()]),
+ case net_kernel:start([list_to_atom(CtlNodeName), name_type()]) of
+ {ok, _} -> ok;
+ {error, Reason} -> throw({error, {distribution_failed, Reason}})
+ end.
+
+name_type() ->
+ case os:getenv("RABBITMQ_USE_LONGNAME") of
+ "true" -> longnames;
+ _ -> shortnames
+ end.
+
usage(Mod) ->
io:format("~s", [Mod:usage()]),
rabbit_misc:quit(1).
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index 6e789e3756..e5a28b559d 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -121,7 +121,6 @@
%%----------------------------------------------------------------------------
start() ->
- start_distribution(),
rabbit_cli:main(
fun (Args, NodeStr) ->
parse_arguments(Args, NodeStr)
@@ -584,28 +583,18 @@ exit_loop(Port) ->
{Port, _} -> exit_loop(Port)
end.
-start_distribution() ->
- CtlNodeName = rabbit_misc:format("rabbitmqctl-~s", [os:getpid()]),
- {ok, _} = net_kernel:start([list_to_atom(CtlNodeName), name_type()]).
-
become(BecomeNode) ->
case net_adm:ping(BecomeNode) of
pong -> exit({node_running, BecomeNode});
pang -> io:format(" * Impersonating node: ~s...", [BecomeNode]),
error_logger:tty(false),
ok = net_kernel:stop(),
- {ok, _} = net_kernel:start([BecomeNode, name_type()]),
+ {ok, _} = net_kernel:start([BecomeNode,rabbit_cli:name_type()]),
io:format(" done~n", []),
Dir = mnesia:system_info(directory),
io:format(" * Mnesia directory : ~s~n", [Dir])
end.
-name_type() ->
- case os:getenv("RABBITMQ_USE_LONGNAME") of
- "true" -> longnames;
- _ -> shortnames
- end.
-
%%----------------------------------------------------------------------------
default_if_empty(List, Default) when is_list(List) ->