From 8abcf21293c5c2db70784121946e896a7d998876 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 26 Feb 2012 18:03:12 +0000 Subject: beginnings of dynamic configuration change by (re)reading config files --- src/rabbit.erl | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file 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 @@ -564,6 +602,13 @@ insert_default_data() -> DefaultReadPerm), ok. +%%--------------------------------------------------------------------------- +%% config change + +change_param(Param, Val) -> + io:format("changing param ~p to ~p~n", [Param, Val]), + ok. + %%--------------------------------------------------------------------------- %% logging -- cgit v1.2.1