summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Bakken <lbakken@pivotal.io>2018-09-06 07:49:19 -0700
committerLuke Bakken <lbakken@pivotal.io>2018-09-06 17:04:49 -0700
commit11915db3bad8f9d226e4a1c443d4e971e624389d (patch)
tree10698974ad12857057c74e03bda77d788a0a238b /src
parent7ef3b27c78673a94ef157bb1158bc321db146a2e (diff)
downloadrabbitmq-server-git-11915db3bad8f9d226e4a1c443d4e971e624389d.tar.gz
Format errors and warnings with regard to config files in a manner similar to lager
Use exit code 64 when configuration is invalid Correctly deal with RABBITMQ_PID_FILE Fix bug in setting up RABBITMQ_PID_FILE as well as printing multi-line warnings and errors Calculate indent
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl2
-rw-r--r--src/rabbit_config.erl33
-rw-r--r--src/rabbit_prelaunch.erl10
3 files changed, 29 insertions, 16 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 6f36de0aa5..f90e42454f 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -880,7 +880,7 @@ boot_error(Class, Reason) ->
log_boot_error_and_exit(Reason, Format, Args) ->
rabbit_log:error(Format, Args),
- io:format("~nBOOT FAILED~n===========~n" ++ Format ++ "~n", Args),
+ io:format(standard_error, "~nBOOT FAILED~n===========~n" ++ Format ++ "~n", Args),
timer:sleep(1000),
exit(Reason).
diff --git a/src/rabbit_config.erl b/src/rabbit_config.erl
index 43248df60e..a18e3888c5 100644
--- a/src/rabbit_config.erl
+++ b/src/rabbit_config.erl
@@ -255,30 +255,38 @@ assert_config(none, _) -> ok;
assert_config(Filename, Env) ->
assert_config(filename:extension(Filename), Filename, Env).
+-define(ERRMSG_INDENT, " ").
+
assert_config(".config", Filename, Env) ->
case filelib:is_regular(Filename) of
true ->
case file:consult(Filename) of
{ok, []} -> {error,
- {"ERROR: Config file ~s should not be empty: ~s",
+ {"Config file ~s should not be empty: ~s",
[Env, Filename]}};
{ok, [_]} -> ok;
{ok, [_|_]} -> {error,
- {"ERROR: Config file ~s must contain ONE list ended by <dot>: ~s",
+ {"Config file ~s must contain ONE list ended by <dot>: ~s",
[Env, Filename]}};
{error, {1, erl_parse, Err}} ->
- {error, {"ERROR: Unable to parse erlang terms from ~s file: ~s~n"
- "ERROR: Reason: ~p~n"
- "ERROR: Check that the file is in the erlang terms format. " ++
+ % Note: the sequence of spaces is to indent from the [error] prefix, like this:
+ %
+ % 2018-09-06 07:05:40.225 [error] Unable to parse erlang terms from RABBITMQ_ADVANCED_CONFIG_FILE...
+ % Reason: ["syntax error before: ",[]]
+ {error, {"Unable to parse erlang terms from ~s file: ~s~n"
+ ?ERRMSG_INDENT
+ "Reason: ~p~n"
+ ?ERRMSG_INDENT
+ "Check that the file is in erlang term format. " ++
case Env of
"RABBITMQ_CONFIG_FILE" ->
- "If you are using the new ini-style format, the file "
- "extension should be '.conf'~n";
+ "If you are using the new ini-style format, the file extension should be '.conf'~n";
_ -> ""
end,
[Env, Filename, Err]}};
{error, Err} ->
- {error, {"ERROR Unable to parse erlang terms from ~s file: ~s~n"
+ {error, {"Unable to parse erlang terms from ~s file: ~s~n"
+ ?ERRMSG_INDENT
"Error: ~p~n",
[Env, Filename, Err]}}
end;
@@ -286,7 +294,7 @@ assert_config(".config", Filename, Env) ->
ok
end;
assert_config(BadExt, Filename, Env) ->
- {error, {"ERROR: '~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.
+ {error, {"'~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.
assert_conf("", _) -> ok;
assert_conf(Filename, Env) ->
@@ -298,8 +306,9 @@ assert_conf(".conf", Filename, Env) ->
case file:consult(Filename) of
{ok, []} -> ok;
{ok, _} ->
- {error, {"ERROR: Wrong format of the config file ~s: ~s~n"
- "ERROR: Check that the file is in the new ini-style config format "
+ {error, {"Wrong format of the config file ~s: ~s~n"
+ ?ERRMSG_INDENT
+ "Check that the file is in the new ini-style config format. "
"If you are using the old format the file extension should "
"be .config~n",
[Env, Filename]}};
@@ -310,4 +319,4 @@ assert_conf(".conf", Filename, Env) ->
ok
end;
assert_conf(BadExt, Filename, Env) ->
- {error, {"ERROR: '~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.
+ {error, {"'~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.
diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl
index 1231f0090e..e43cba728a 100644
--- a/src/rabbit_prelaunch.erl
+++ b/src/rabbit_prelaunch.erl
@@ -26,6 +26,7 @@
-define(SET_DIST_PORT, 0).
-define(ERROR_CODE, 1).
-define(DO_NOT_SET_DIST_PORT, 2).
+-define(EX_USAGE, 64).
%%----------------------------------------------------------------------------
%% Specs
@@ -62,9 +63,12 @@ stop() ->
config_file_check() ->
case rabbit_config:validate_config_files() of
ok -> ok;
- {error, {Err, Args}} ->
- io:format(Err, Args),
- rabbit_misc:quit(?ERROR_CODE)
+ {error, {ErrFmt, ErrArgs}} ->
+ ErrMsg = io_lib:format(ErrFmt, ErrArgs),
+ {{Year, Month, Day}, {Hour, Minute, Second, Milli}} = lager_util:localtime_ms(),
+ io:format(standard_error, "~b-~2..0b-~2..0b ~2..0b:~2..0b:~2..0b.~b [error] ~s",
+ [Year, Month, Day, Hour, Minute, Second, Milli, ErrMsg]),
+ rabbit_misc:quit(?EX_USAGE)
end.
%% Check whether a node with the same name is already running