summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-04-20 22:35:52 -0400
committerFred Hebert <mononcqc@ferd.ca>2018-04-20 22:40:21 -0400
commit8e165d0cc8b80cd3f5a9f31964254b9a9d5212f5 (patch)
treef54ef2e8709f9a41d156e77162b61ded2738efba /src
parentd4c529a4702128761f7919a81b7ce88bf39809d9 (diff)
Reload apps running in shell with new config
This patch makes it so that whenever the rebar3 shell has a new configuration for an application that is already running and would be restarted (without risking the stability of the node or functionality of rebar_agent), we stop and restart the app.
Diffstat (limited to 'src')
-rw-r--r--src/rebar_prv_shell.erl31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index 47e0366..2c48083 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -271,11 +271,11 @@ maybe_boot_apps(State) ->
case find_apps_to_boot(State) of
undefined ->
%% try to read in sys.config file
- ok = reread_config(State);
+ ok = reread_config([], State);
Apps ->
%% load apps, then check config, then boot them.
load_apps(Apps),
- ok = reread_config(State),
+ ok = reread_config(Apps, State),
boot_apps(Apps)
end.
@@ -340,11 +340,36 @@ load_apps(Apps) ->
not lists:keymember(App, 1, application:loaded_applications())],
ok.
-reread_config(State) ->
+reread_config(AppsToStart, State) ->
case find_config(State) of
no_config ->
ok;
ConfigList ->
+ %% This allows people who use applications that are also
+ %% depended on by rebar3 or its plugins to change their
+ %% configuration at runtime based on the configuration files.
+ %%
+ %% To do this, we stop apps that are already started before
+ %% reloading their configuration.
+ %%
+ %% We make an exception for apps that:
+ %% - are not already running
+ %% - would not be restarted (and hence would break some
+ %% compatibility with rebar3)
+ %% - are not in the config files and would see no config
+ %% changes
+ %% - are not in a blacklist, where changing their config
+ %% would be risky to the shell or the rebar3 agent
+ %% functionality (i.e. changing inets may break proxy
+ %% settings, stopping `kernel' would break everything)
+ Running = [App || {App, _, _} <- application:which_applications()],
+ BlackList = [inets, stdlib, kernel, rebar],
+ _ = [application:stop(App)
+ || Config <- ConfigList,
+ {App, _} <- Config,
+ lists:member(App, Running),
+ lists:member(App, AppsToStart),
+ not lists:member(App, BlackList)],
_ = rebar_utils:reread_config(ConfigList),
ok
end.