Skip to content

Commit 9dd6442

Browse files
author
Matthias Radestock
committed
merge bug21669 into default
2 parents 8d4e9e4 + bd9b004 commit 9dd6442

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

scripts/rabbitmq-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fi
7474

7575
RABBITMQ_START_RABBIT=
7676
[ "x" = "x$RABBITMQ_ALLOW_INPUT" ] && RABBITMQ_START_RABBIT='-noinput'
77-
[ "x" = "x$RABBITMQ_NODE_ONLY" ] && RABBITMQ_START_RABBIT="${RABBITMQ_START_RABBIT} -s rabbit"
7877

7978
RABBITMQ_EBIN_ROOT="${RABBITMQ_HOME}/ebin"
8079
if [ -f "${RABBITMQ_EBIN_ROOT}/rabbit.boot" ] && [ "x" = "x$RABBITMQ_NODE_ONLY" ]; then
@@ -83,6 +82,7 @@ if [ -f "${RABBITMQ_EBIN_ROOT}/rabbit.boot" ] && [ "x" = "x$RABBITMQ_NODE_ONLY"
8382
else
8483
RABBITMQ_BOOT_FILE=start_sasl
8584
RABBITMQ_EBIN_PATH="-pa ${RABBITMQ_EBIN_ROOT}"
85+
[ "x" = "x$RABBITMQ_NODE_ONLY" ] && RABBITMQ_START_RABBIT="${RABBITMQ_START_RABBIT} -s rabbit"
8686
fi
8787

8888
# we need to turn off path expansion because some of the vars, notably

src/rabbit.erl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
-behaviour(application).
3535

36-
-export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]).
36+
-export([prepare/0, start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]).
3737

3838
-export([start/2, stop/1]).
3939

@@ -57,6 +57,7 @@
5757
-type(log_location() :: 'tty' | 'undefined' | string()).
5858
-type(file_suffix() :: binary()).
5959

60+
-spec(prepare/0 :: () -> 'ok').
6061
-spec(start/0 :: () -> 'ok').
6162
-spec(stop/0 :: () -> 'ok').
6263
-spec(stop_and_halt/0 :: () -> 'ok').
@@ -71,11 +72,14 @@
7172

7273
%%----------------------------------------------------------------------------
7374

75+
prepare() ->
76+
ok = ensure_working_log_handlers(),
77+
ok = rabbit_mnesia:ensure_mnesia_dir().
78+
7479
start() ->
7580
try
76-
ok = ensure_working_log_handlers(),
77-
ok = rabbit_mnesia:ensure_mnesia_dir(),
78-
ok = rabbit_misc:start_applications(?APPS)
81+
ok = prepare(),
82+
ok = rabbit_misc:start_applications(?APPS)
7983
after
8084
%%give the error loggers some time to catch up
8185
timer:sleep(100)

src/rabbit_plugin_activator.erl

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ start() ->
4949
UnpackedPluginDir = get_env(plugins_expand_dir, ?DefaultUnpackedPluginDir),
5050
RabbitEBin = get_env(rabbit_ebin, ?DefaultRabbitEBin),
5151

52+
RootName = RabbitEBin ++ "/rabbit",
53+
5254
%% Unpack any .ez plugins
5355
unpack_ez_plugins(PluginDir, UnpackedPluginDir),
5456

@@ -60,10 +62,8 @@ start() ->
6062
%% Build the entire set of dependencies - this will load the
6163
%% applications along the way
6264
AllApps = case catch sets:to_list(expand_dependencies(RequiredApps)) of
63-
{unknown_app, {App, Err}} ->
64-
io:format("ERROR: Failed to load application " ++
65-
"~s: ~p~n", [App, Err]),
66-
halt(1);
65+
{failed_to_load_app, App, Err} ->
66+
error("failed to load application ~s: ~p", [App, Err]);
6767
AppList ->
6868
AppList
6969
end,
@@ -77,11 +77,11 @@ start() ->
7777
AppVersions},
7878

7979
%% Write it out to ebin/rabbit.rel
80-
file:write_file(RabbitEBin ++ "/rabbit.rel",
81-
io_lib:format("~p.~n", [RDesc])),
80+
file:write_file(RootName ++ ".rel", io_lib:format("~p.~n", [RDesc])),
8281

8382
%% Compile the script
84-
case systools:make_script(RabbitEBin ++ "/rabbit", [local, silent]) of
83+
ScriptFile = RootName ++ ".script",
84+
case systools:make_script(RootName, [local, silent]) of
8585
{ok, Module, Warnings} ->
8686
%% This gets lots of spurious no-source warnings when we
8787
%% have .ez files, so we want to supress them to prevent
@@ -98,9 +98,19 @@ start() ->
9898
end,
9999
ok;
100100
{error, Module, Error} ->
101-
io:format("Boot file generation failed: ~s~n",
102-
[Module:format_error(Error)]),
103-
halt(1)
101+
error("generation of boot script file ~s failed: ~w",
102+
[ScriptFile, Module:format_error(Error)])
103+
end,
104+
105+
case post_process_script(ScriptFile) of
106+
ok -> ok;
107+
{error, Reason} ->
108+
error("post processing of boot script file ~s failed: ~w",
109+
[ScriptFile, Reason])
110+
end,
111+
case systools:script2boot(RootName) of
112+
ok -> ok;
113+
error -> error("failed to compile boot script file ~s", [ScriptFile])
104114
end,
105115
halt(),
106116
ok.
@@ -122,10 +132,10 @@ determine_version(App) ->
122132
assert_dir(Dir) ->
123133
case filelib:is_dir(Dir) of
124134
true -> ok;
125-
false ->
126-
ok = filelib:ensure_dir(Dir),
127-
ok = file:make_dir(Dir)
135+
false -> ok = filelib:ensure_dir(Dir),
136+
ok = file:make_dir(Dir)
128137
end.
138+
129139
delete_dir(Dir) ->
130140
case filelib:is_dir(Dir) of
131141
true ->
@@ -143,6 +153,7 @@ delete_dir(Dir) ->
143153
false ->
144154
ok
145155
end.
156+
146157
is_symlink(Name) ->
147158
case file:read_link(Name) of
148159
{ok, _} -> true;
@@ -185,14 +196,43 @@ expand_dependencies(Current, [Next|Rest]) ->
185196
expand_dependencies(Current, Rest);
186197
false ->
187198
case application:load(Next) of
188-
ok ->
199+
ok ->
189200
ok;
190-
{error, {already_loaded, _}} ->
201+
{error, {already_loaded, _}} ->
191202
ok;
192-
X ->
193-
throw({unknown_app, {Next, X}})
203+
{error, Reason} ->
204+
throw({failed_to_load_app, Next, Reason})
194205
end,
195206
{ok, Required} = application:get_key(Next, applications),
196207
Unique = [A || A <- Required, not(sets:is_element(A, Current))],
197208
expand_dependencies(sets:add_element(Next, Current), Rest ++ Unique)
198209
end.
210+
211+
post_process_script(ScriptFile) ->
212+
case file:consult(ScriptFile) of
213+
{ok, [{script, Name, Entries}]} ->
214+
NewEntries = process_entries(Entries),
215+
case file:open(ScriptFile, [write]) of
216+
{ok, Fd} ->
217+
io:format(Fd, "%% script generated at ~w ~w~n~p.~n",
218+
[date(), time(), {script, Name, NewEntries}]),
219+
file:close(Fd),
220+
ok;
221+
{error, OReason} ->
222+
{error, {failed_to_open_script_file_for_writing, OReason}}
223+
end;
224+
{error, Reason} ->
225+
{error, {failed_to_load_script, Reason}}
226+
end.
227+
228+
process_entries([]) ->
229+
[];
230+
process_entries([Entry = {apply,{application,start_boot,[stdlib,permanent]}} |
231+
Rest]) ->
232+
[Entry, {apply,{rabbit,prepare,[]}} | Rest];
233+
process_entries([Entry|Rest]) ->
234+
[Entry | process_entries(Rest)].
235+
236+
error(Fmt, Args) ->
237+
io:format("ERROR: " ++ Fmt ++ "~n", Args),
238+
halt(1).

0 commit comments

Comments
 (0)