summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-09-30 21:26:56 +0100
committerMatthias Radestock <matthias@lshift.net>2009-09-30 21:26:56 +0100
commitd1b33ecf9a708b4d09cac871f471d6b58c90f1c3 (patch)
tree232199dba40dcd3bf6cd1718b182f14e377ea667
parent8857b55e46506c13386c3f13f6c3f3b6b942a876 (diff)
downloadrabbitmq-server-bug21669.tar.gz
leave error reporting in rabbit:prepare to contextbug21669
also: - tabs->spaces - a few cosmetic changes - extract error handling & termination in rabbit_plugin_activator
-rw-r--r--src/rabbit.erl16
-rw-r--r--src/rabbit_plugin_activator.erl93
2 files changed, 54 insertions, 55 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index d4542a1e..cac64cb4 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -57,9 +57,9 @@
-type(log_location() :: 'tty' | 'undefined' | string()).
-type(file_suffix() :: binary()).
+-spec(prepare/0 :: () -> 'ok').
-spec(start/0 :: () -> 'ok').
-spec(stop/0 :: () -> 'ok').
--spec(prepare/0 :: () -> 'ok').
-spec(stop_and_halt/0 :: () -> 'ok').
-spec(rotate_logs/1 :: (file_suffix()) -> 'ok' | {'error', any()}).
-spec(status/0 :: () ->
@@ -73,19 +73,13 @@
%%----------------------------------------------------------------------------
prepare() ->
- try
- ok = ensure_working_log_handlers(),
- ok = rabbit_mnesia:ensure_mnesia_dir()
- catch
- {error, Reason} ->
- io:format("Failed to prepare Rabbit: ~p~n", [Reason]),
- halt(1)
- end.
+ ok = ensure_working_log_handlers(),
+ ok = rabbit_mnesia:ensure_mnesia_dir().
start() ->
try
- prepare(),
- rabbit_misc:start_applications(?APPS)
+ ok = prepare(),
+ ok = rabbit_misc:start_applications(?APPS)
after
%%give the error loggers some time to catch up
timer:sleep(100)
diff --git a/src/rabbit_plugin_activator.erl b/src/rabbit_plugin_activator.erl
index c85f4b1c..f28c4a6e 100644
--- a/src/rabbit_plugin_activator.erl
+++ b/src/rabbit_plugin_activator.erl
@@ -49,6 +49,8 @@ start() ->
UnpackedPluginDir = get_env(plugins_expand_dir, ?DefaultUnpackedPluginDir),
RabbitEBin = get_env(rabbit_ebin, ?DefaultRabbitEBin),
+ RootName = RabbitEBin ++ "/rabbit",
+
%% Unpack any .ez plugins
unpack_ez_plugins(PluginDir, UnpackedPluginDir),
@@ -60,10 +62,8 @@ start() ->
%% Build the entire set of dependencies - this will load the
%% applications along the way
AllApps = case catch sets:to_list(expand_dependencies(RequiredApps)) of
- {unknown_app, {App, Err}} ->
- io:format("ERROR: Failed to load application " ++
- "~s: ~p~n", [App, Err]),
- halt(1);
+ {failed_to_load_app, App, Err} ->
+ error("failed to load application ~s: ~p", [App, Err]);
AppList ->
AppList
end,
@@ -77,11 +77,11 @@ start() ->
AppVersions},
%% Write it out to ebin/rabbit.rel
- file:write_file(RabbitEBin ++ "/rabbit.rel",
- io_lib:format("~p.~n", [RDesc])),
+ file:write_file(RootName ++ ".rel", io_lib:format("~p.~n", [RDesc])),
%% Compile the script
- case systools:make_script(RabbitEBin ++ "/rabbit", [local, silent]) of
+ ScriptFile = RootName ++ ".script",
+ case systools:make_script(RootName, [local, silent]) of
{ok, Module, Warnings} ->
%% This gets lots of spurious no-source warnings when we
%% have .ez files, so we want to supress them to prevent
@@ -98,20 +98,20 @@ start() ->
end,
ok;
{error, Module, Error} ->
- io:format("Boot file generation failed: ~s~n",
- [Module:format_error(Error)]),
- halt(1)
+ error("generation of boot script file ~s failed: ~w",
+ [ScriptFile, Module:format_error(Error)])
end,
- case catch include_rabbit_prepare(RabbitEBin ++ "/rabbit") of
+ case post_process_script(ScriptFile) of
ok -> ok;
- {error, Message} -> io:format("~s~n", [Message]),
- halt(1)
+ {error, Reason} ->
+ error("post processing of boot script file ~s failed: ~w",
+ [ScriptFile, Reason])
+ end,
+ case systools:script2boot(RootName) of
+ ok -> ok;
+ error -> error("failed to compile boot script file ~s", [ScriptFile])
end,
- case systools:script2boot(RabbitEBin ++ "/rabbit") of
- ok -> ok;
- error -> io:format("Failed to compile updated rabbit.script~n")
- end,
halt(),
ok.
@@ -132,10 +132,10 @@ determine_version(App) ->
assert_dir(Dir) ->
case filelib:is_dir(Dir) of
true -> ok;
- false ->
- ok = filelib:ensure_dir(Dir),
- ok = file:make_dir(Dir)
+ false -> ok = filelib:ensure_dir(Dir),
+ ok = file:make_dir(Dir)
end.
+
delete_dir(Dir) ->
case filelib:is_dir(Dir) of
true ->
@@ -153,6 +153,7 @@ delete_dir(Dir) ->
false ->
ok
end.
+
is_symlink(Name) ->
case file:read_link(Name) of
{ok, _} -> true;
@@ -195,39 +196,43 @@ expand_dependencies(Current, [Next|Rest]) ->
expand_dependencies(Current, Rest);
false ->
case application:load(Next) of
- ok ->
+ ok ->
ok;
- {error, {already_loaded, _}} ->
+ {error, {already_loaded, _}} ->
ok;
- X ->
- throw({unknown_app, {Next, X}})
+ {error, Reason} ->
+ throw({failed_to_load_app, Next, Reason})
end,
{ok, Required} = application:get_key(Next, applications),
Unique = [A || A <- Required, not(sets:is_element(A, Current))],
expand_dependencies(sets:add_element(Next, Current), Rest ++ Unique)
end.
-include_rabbit_prepare(RootName) ->
- ScriptFile = RootName ++ ".script",
- case file:consult(ScriptFile) of
- {ok, [{script, Name, Entries}]} ->
- NewEntries = process_entries(Entries),
- case file:open(ScriptFile, [write]) of
- {ok, Fd} ->
- io:format(Fd, "%% script generated at ~w ~w\n~p.\n",
- [date(), time(), {script, Name, NewEntries}]),
- file:close(Fd),
- ok;
- {error, OReason} ->
- {error, {failed_to_open_boot_for_writing, OReason}}
- end;
- {error, Reason} ->
- {error, {failed_to_load_script, Reason}}
+post_process_script(ScriptFile) ->
+ case file:consult(ScriptFile) of
+ {ok, [{script, Name, Entries}]} ->
+ NewEntries = process_entries(Entries),
+ case file:open(ScriptFile, [write]) of
+ {ok, Fd} ->
+ io:format(Fd, "%% script generated at ~w ~w~n~p.~n",
+ [date(), time(), {script, Name, NewEntries}]),
+ file:close(Fd),
+ ok;
+ {error, OReason} ->
+ {error, {failed_to_open_script_file_for_writing, OReason}}
+ end;
+ {error, Reason} ->
+ {error, {failed_to_load_script, Reason}}
end.
process_entries([]) ->
- [];
-process_entries([Entry = {apply,{application,start_boot,[stdlib,permanent]}}|Rest]) ->
- [Entry, {apply,{rabbit,prepare,[]}} | Rest];
+ [];
+process_entries([Entry = {apply,{application,start_boot,[stdlib,permanent]}} |
+ Rest]) ->
+ [Entry, {apply,{rabbit,prepare,[]}} | Rest];
process_entries([Entry|Rest]) ->
- [Entry | process_entries(Rest)]. \ No newline at end of file
+ [Entry | process_entries(Rest)].
+
+error(Fmt, Args) ->
+ io:format("ERROR: " ++ Fmt ++ "~n", Args),
+ halt(1).