diff options
author | Tim Watson <tim@rabbitmq.com> | 2014-03-18 20:25:11 +0000 |
---|---|---|
committer | Tim Watson <tim@rabbitmq.com> | 2014-03-18 20:25:11 +0000 |
commit | 87a1e06d6834e3740ac21034ce110b24ea693e9b (patch) | |
tree | 7142853c50b8176f762cbdf2d76addf48eba6a1f /src/rabbit_plugins.erl | |
parent | ec5086953c6b6739255041b9d30d420257f2ceba (diff) | |
parent | 19767b76842b73006d6840950d572a777077eadf (diff) | |
download | rabbitmq-server-87a1e06d6834e3740ac21034ce110b24ea693e9b.tar.gz |
Merge default into bug24926
Diffstat (limited to 'src/rabbit_plugins.erl')
-rw-r--r-- | src/rabbit_plugins.erl | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index 4ac6c4a0..d3d76be0 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -18,6 +18,7 @@ -include("rabbit.hrl"). -export([setup/0, active/0, read_enabled/1, list/1, dependencies/3]). +-export([enable/1, disable/1]). %%---------------------------------------------------------------------------- @@ -31,17 +32,35 @@ -spec(read_enabled/1 :: (file:filename()) -> [plugin_name()]). -spec(dependencies/3 :: (boolean(), [plugin_name()], [#plugin{}]) -> [plugin_name()]). - +-spec(enable/1 :: ([plugin_name()]) -> 'ok'). +-spec(disable/1 :: ([plugin_name()]) -> 'ok'). -endif. %%---------------------------------------------------------------------------- +enable(Plugins) -> + prepare_plugins(Plugins), + Diff = rabbit:start_apps(Plugins), + ok = rabbit_event:notify(plugins_changed, [{enabled, Diff}]). + +disable(Plugins) -> + Diff = rabbit:stop_apps(Plugins), + ok = rabbit_event:notify(plugins_changed, [{disabled, Plugins}]). + %% @doc Prepares the file system and installs all enabled plugins. setup() -> - {ok, PluginDir} = application:get_env(rabbit, plugins_dir), {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), + + %% Eliminate the contents of the destination directory + case delete_recursively(ExpandDir) of + ok -> ok; + {error, E1} -> throw({error, {cannot_delete_plugins_expand_dir, + [ExpandDir, E1]}}) + end, + {ok, EnabledFile} = application:get_env(rabbit, enabled_plugins_file), - prepare_plugins(EnabledFile, PluginDir, ExpandDir). + Enabled = read_enabled(EnabledFile), + prepare_plugins(Enabled). %% @doc Lists the plugins which are currently running. active() -> @@ -104,9 +123,11 @@ dependencies(Reverse, Sources, AllPlugins) -> %%---------------------------------------------------------------------------- -prepare_plugins(EnabledFile, PluginsDistDir, ExpandDir) -> +prepare_plugins(Enabled) -> + {ok, PluginsDistDir} = application:get_env(rabbit, plugins_dir), + {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), + AllPlugins = list(PluginsDistDir), - Enabled = read_enabled(EnabledFile), ToUnpack = dependencies(false, Enabled, AllPlugins), ToUnpackPlugins = lookup_plugins(ToUnpack, AllPlugins), @@ -117,12 +138,6 @@ prepare_plugins(EnabledFile, PluginsDistDir, ExpandDir) -> [Missing]) end, - %% Eliminate the contents of the destination directory - case delete_recursively(ExpandDir) of - ok -> ok; - {error, E1} -> throw({error, {cannot_delete_plugins_expand_dir, - [ExpandDir, E1]}}) - end, case filelib:ensure_dir(ExpandDir ++ "/") of ok -> ok; {error, E2} -> throw({error, {cannot_create_plugins_expand_dir, |