summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Majkowski <majek@lshift.net>2009-09-22 14:11:14 +0100
committerMarek Majkowski <majek@lshift.net>2009-09-22 14:11:14 +0100
commit90251e578e84ba5ad88ff3b1f2ece8b2448e3ee4 (patch)
treea167c17932edf70bf275802c48fadb92c256445c
parentc14bacabe348c83f7434575a55cfd2fd3aa23e84 (diff)
downloadrabbitmq-server-90251e578e84ba5ad88ff3b1f2ece8b2448e3ee4.tar.gz
halt moved to rabbit:start/0 instead of rabbit:star/2, added magic error catcher to produce better error message
-rw-r--r--src/rabbit.erl43
-rw-r--r--src/rabbit_networking.erl4
-rw-r--r--src/rabbit_startup_error_logger.erl78
3 files changed, 103 insertions, 22 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index a54fc48e..4b330d5f 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -71,7 +71,30 @@
%%----------------------------------------------------------------------------
-start() ->
+fatal(Reason) ->
+ io:format("~n~n"),
+ io:format(" [*] Startup failed: ~p~n", [Reason]),
+ io:format(" [*] QUITTING!~n"),
+ timer:sleep(100), % higher chances to flush i/o correctly
+ halt(255).
+
+start() ->
+ ok = error_logger:add_report_handler(rabbit_startup_error_logger, []),
+ R = try do_start() of
+ X -> X
+ catch
+ {error, TracebackReason} ->
+ Reason = case rabbit_startup_error_logger:get_first_error() of
+ {ok, ErrorReason} -> string:strip(ErrorReason);
+ _ -> TracebackReason
+ end,
+ fatal(Reason)
+ end,
+ terminated_ok = error_logger:delete_report_handler(
+ rabbit_startup_error_logger),
+ R.
+
+do_start() ->
try
ok = ensure_working_log_handlers(),
ok = rabbit_mnesia:ensure_mnesia_dir(),
@@ -110,25 +133,7 @@ rotate_logs(BinarySuffix) ->
%%--------------------------------------------------------------------
-fatal(Reason) ->
- io:format("~n~n"),
- io:format(" [*] Startup failed: ~p~n", [Reason]),
- io:format(" [*] QUITTING!~n"),
- timer:sleep(100), % higher chances to flush i/o
- halt(255).
-
start(normal, []) ->
- try do_start() of
- X -> X
- catch
- {error, Reason, Args} ->
- fatal({Reason, Args});
- {error, Reason} ->
- fatal(Reason)
- end.
-
-do_start() ->
-
{ok, SupPid} = rabbit_sup:start_link(),
print_banner(),
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index f7007c61..8507fcd5 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -127,9 +127,7 @@ start_listener(Host, Port, Label, OnConnect) ->
OnConnect, Label]},
transient, infinity, supervisor, [tcp_listener_sup]}) of
{ok, _} -> ok;
- {error, _Reason} -> error_logger:error_msg("failed to bind ~p to ~p:~p~n",
- [Label, Host, Port]),
- throw({error, {failed_to_bind, Host, Port}})
+ {error, Reason} -> throw({error, {failed_to_bind, Host, Port, Reason}})
end,
ok.
diff --git a/src/rabbit_startup_error_logger.erl b/src/rabbit_startup_error_logger.erl
new file mode 100644
index 00000000..18e27885
--- /dev/null
+++ b/src/rabbit_startup_error_logger.erl
@@ -0,0 +1,78 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License at
+%% http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developers of the Original Code are LShift Ltd,
+%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
+%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
+%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
+%% Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
+%% Ltd. Portions created by Cohesive Financial Technologies LLC are
+%% Copyright (C) 2007-2009 Cohesive Financial Technologies
+%% LLC. Portions created by Rabbit Technologies Ltd are Copyright
+%% (C) 2007-2009 Rabbit Technologies Ltd.
+%%
+%% All Rights Reserved.
+%%
+%% Contributor(s): ______________________________________.
+%%
+
+-module(rabbit_startup_error_logger).
+-include("rabbit.hrl").
+-include("rabbit_framing.hrl").
+
+-behaviour(gen_event).
+
+-export([init/1, terminate/2, code_change/3, handle_call/2, handle_event/2,
+ handle_info/2, get_first_error/0]).
+
+init([]) -> {ok, {}}.
+
+terminate(_Arg, _State) ->
+ terminated_ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+get_first_error() ->
+ gen_event:call(error_logger, ?MODULE, get_first_error).
+
+handle_call(get_first_error, State) ->
+ Ret = case State of
+ {error, Res} -> {ok, Res};
+ _ -> {error}
+ end,
+ {ok, Ret, State};
+
+handle_call(_Request, State) ->
+ {ok, not_understood, State}.
+
+
+handle_event({Kind, _Gleader, {_Pid, Format, Data}}, State={}) ->
+ case Kind of
+ error -> Res = string:strip(
+ lists:flatten(io_lib:format(Format, Data)),
+ both, $\n),
+ {ok, {error, Res}};
+ _ -> {ok, State}
+ end;
+
+handle_event(_Event, State) ->
+ {ok, State}.
+
+
+handle_info(_Info, State) ->
+ {ok, State}.
+