summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-02-26 18:03:12 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2012-02-26 18:03:12 +0000
commit8abcf21293c5c2db70784121946e896a7d998876 (patch)
tree546fea45028566991b44c7675a2759fe48b01e0a
parent597061c35fe855f9f803cac97a4aa6be419a6cd3 (diff)
downloadrabbitmq-server-bug24762.tar.gz
beginnings of dynamic configuration change by (re)reading config filesbug24762
-rw-r--r--src/rabbit.erl49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index dd5fb89c..3e495ece 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -19,10 +19,10 @@
-behaviour(application).
-export([maybe_hipe_compile/0, prepare/0, start/0, stop/0, stop_and_halt/0,
- status/0, is_running/0, is_running/1, environment/0,
+ change_config/0, status/0, is_running/0, is_running/1, environment/0,
rotate_logs/1, force_event_refresh/0]).
--export([start/2, stop/1]).
+-export([start/2, stop/1, config_change/3]).
-export([log_location/1]). %% for testing
@@ -219,6 +219,7 @@
-spec(start/0 :: () -> 'ok').
-spec(stop/0 :: () -> 'ok').
-spec(stop_and_halt/0 :: () -> no_return()).
+-spec(change_config/0 :: () -> rabbit_types:ok_or_error(any())).
-spec(status/0 ::
() -> [{pid, integer()} |
{running_applications, [{atom(), string(), string()}]} |
@@ -240,6 +241,8 @@
{'required',[any(),...]}}} |
{'ok',pid()}).
-spec(stop/1 :: (_) -> 'ok').
+-spec(config_change/3 ::
+ ([{param(), term()}], [{param(), term()}], [param{}]) -> 'ok').
-spec(maybe_insert_default_data/0 :: () -> 'ok').
-spec(boot_delegate/0 :: () -> 'ok').
@@ -316,6 +319,23 @@ stop_and_halt() ->
end,
ok.
+change_config() ->
+ EnvBefore = application_controller:prep_config_change(),
+ AppSpecL = [begin
+ {ok, [AppSpec]} = file:consult(
+ code:where_is_file(
+ atom_to_list(App) ++ ".app")),
+ AppSpec
+ end || {App, _,_} <- application:which_applications()],
+ ConfFiles = case init:get_argument(config) of
+ {ok, Files} -> [File || [File] <- Files];
+ error -> []
+ end,
+ case application_controller:change_application_data(AppSpecL, ConfFiles) of
+ ok -> application_controller:config_change(EnvBefore);
+ {error, Reason} -> {error, Reason}
+ end.
+
status() ->
S1 = [{pid, list_to_integer(os:getpid())},
{running_applications, application:which_applications(infinity)},
@@ -388,6 +408,24 @@ stop(_State) ->
end,
ok.
+config_change(Changed, [], []) ->
+ case lists:flatmap(fun ({Param, Val}) -> case change_param(Param, Val) of
+ ok -> [];
+ {error, Error} -> [Error]
+ end
+ end, Changed) of
+ [] -> ok;
+ Errors -> {error, Errors}
+ end;
+
+config_change(Changed, New, Removed) ->
+ {error, [{unexpected_new_or_removed_rabbit_application_parameters,
+ {new, New}, {removed, Removed}} |
+ case config_change(Changed, [], []) of
+ ok -> [];
+ {error, Errors} -> Errors
+ end]}.
+
%%---------------------------------------------------------------------------
%% application life cycle
@@ -565,6 +603,13 @@ insert_default_data() ->
ok.
%%---------------------------------------------------------------------------
+%% config change
+
+change_param(Param, Val) ->
+ io:format("changing param ~p to ~p~n", [Param, Val]),
+ ok.
+
+%%---------------------------------------------------------------------------
%% logging
ensure_working_log_handlers() ->