summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl9
-rw-r--r--src/rabbit_plugin_activator.erl36
2 files changed, 42 insertions, 3 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 27f085c223..242b6cc71f 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -33,7 +33,7 @@
-behaviour(application).
--export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]).
+-export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]).
-export([start/2, stop/1]).
@@ -71,10 +71,13 @@
%%----------------------------------------------------------------------------
+prepare() ->
+ ok = ensure_working_log_handlers(),
+ ok = rabbit_mnesia:ensure_mnesia_dir().
+
start() ->
try
- ok = ensure_working_log_handlers(),
- ok = rabbit_mnesia:ensure_mnesia_dir(),
+ prepare(),
ok = rabbit_misc:start_applications(?APPS)
after
%%give the error loggers some time to catch up
diff --git a/src/rabbit_plugin_activator.erl b/src/rabbit_plugin_activator.erl
index 0206f73e9f..175e496d72 100644
--- a/src/rabbit_plugin_activator.erl
+++ b/src/rabbit_plugin_activator.erl
@@ -102,6 +102,12 @@ start() ->
[Module:format_error(Error)]),
halt(1)
end,
+
+ case catch include_rabbit_prepare(RabbitEBin ++ "/rabbit") of
+ ok -> ok;
+ {error, Message} -> io:format("~s~n", [Message]),
+ halt(1)
+ end,
halt(),
ok.
@@ -196,3 +202,33 @@ expand_dependencies(Current, [Next|Rest]) ->
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",
+ {SName, SNewEntries} = case file:consult(RootName ++ ".script") of
+ {ok, [{script, Name, Entries}]} ->
+ NewEntries = process_entries(Entries),
+ {Name, NewEntries};
+ {error, Reason} ->
+ throw({error, io_lib:format("Failed to load script: ~p", [Reason])})
+ end,
+
+ case file:open(ScriptFile, [write]) of
+ {ok, Fd} ->
+ io:format(Fd, "%% script generated at ~w ~w\n~p.\n",
+ [date(), time(), {script, SName, SNewEntries}]),
+ file:close(Fd),
+ ok;
+ {error, OReason} ->
+ throw({error, io_lib:format("Failed to open script file for writing - ~p", [OReason])})
+ end,
+ case systools:script2boot(RootName) of
+ ok -> ok;
+ error -> "Failed to compile script file to boot file"
+ end.
+
+process_entries([]) -> [];
+process_entries([Entry = {apply,{application,start_boot,[stdlib,permanent]}}|Rest]) ->
+ [Entry, {apply,{rabbit,prepare,[]}}] ++ process_entries(Rest);
+process_entries([Entry|Rest]) ->
+ [Entry] ++ process_entries(Rest).