Skip to content

Commit 7fc24e6

Browse files
Alexey Lebedeffmichaelklishin
authored andcommitted
Provide some defaults for embedding
This commit provides defaults for some paths (similar to the thing the mnesia does with its `dir` parameter) that will allow us to start broker in embedded mode without any additional configuration. The minimal test-case is to issue the following commands from `rabbitmq-server` checkout: make shell "SHELL_OPTS=-sname embed-friendly@localhost" > rabbit:start().
1 parent f3798d4 commit 7fc24e6

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/rabbit_mnesia.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,11 @@ with_running_or_clean_mnesia(Fun) ->
840840
case IsMnesiaRunning of
841841
true -> Fun();
842842
false ->
843-
{ok, MnesiaDir} = application:get_env(mnesia, dir),
844843
application:unset_env(mnesia, dir),
845844
mnesia:start(),
846845
Result = Fun(),
847846
application:stop(mnesia),
848-
application:set_env(mnesia, dir, MnesiaDir),
847+
application:set_env(mnesia, dir, dir()),
849848
Result
850849
end.
851850

src/rabbit_plugins.erl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,49 @@ ensure(FileJustChanged0) ->
6161
{error, {enabled_plugins_mismatch, FileJustChanged, OurFile}}
6262
end.
6363

64+
-spec plugins_expand_dir() -> file:filename().
65+
plugins_expand_dir() ->
66+
case application:get_env(rabbit, plugins_expand_dir) of
67+
{ok, ExpandDir} ->
68+
ExpandDir;
69+
_ ->
70+
filename:join([rabbit_mnesia:dir(), "plugins_expand_dir"])
71+
end.
72+
73+
-spec plugins_dist_dir() -> file:filename().
74+
plugins_dist_dir() ->
75+
case application:get_env(rabbit, plugins_dir) of
76+
{ok, PluginsDistDir} ->
77+
PluginsDistDir;
78+
_ ->
79+
filename:join([rabbit_mnesia:dir(), "fake_plugins_dir"])
80+
end.
81+
82+
-spec enabled_plugins() -> [atom()].
83+
enabled_plugins() ->
84+
case application:get_env(rabbit, enabled_plugins_file) of
85+
{ok, EnabledFile} ->
86+
read_enabled(EnabledFile);
87+
_ ->
88+
[]
89+
end.
90+
6491
%% @doc Prepares the file system and installs all enabled plugins.
6592
setup() ->
66-
{ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
67-
93+
ExpandDir = plugins_expand_dir(),
6894
%% Eliminate the contents of the destination directory
6995
case delete_recursively(ExpandDir) of
7096
ok -> ok;
7197
{error, E1} -> throw({error, {cannot_delete_plugins_expand_dir,
7298
[ExpandDir, E1]}})
7399
end,
74100

75-
{ok, EnabledFile} = application:get_env(rabbit, enabled_plugins_file),
76-
Enabled = read_enabled(EnabledFile),
101+
Enabled = enabled_plugins(),
77102
prepare_plugins(Enabled).
78103

79104
%% @doc Lists the plugins which are currently running.
80105
active() ->
81-
{ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
82-
InstalledPlugins = plugin_names(list(ExpandDir)),
106+
InstalledPlugins = plugin_names(list(plugins_expand_dir())),
83107
[App || {App, _, _} <- rabbit_misc:which_applications(),
84108
lists:member(App, InstalledPlugins)].
85109

@@ -163,10 +187,9 @@ is_loadable(App) ->
163187
%%----------------------------------------------------------------------------
164188

165189
prepare_plugins(Enabled) ->
166-
{ok, PluginsDistDir} = application:get_env(rabbit, plugins_dir),
167-
{ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
190+
ExpandDir = plugins_expand_dir(),
168191

169-
AllPlugins = list(PluginsDistDir),
192+
AllPlugins = list(plugins_dist_dir()),
170193
Wanted = dependencies(false, Enabled, AllPlugins),
171194
WantedPlugins = lookup_plugins(Wanted, AllPlugins),
172195

0 commit comments

Comments
 (0)