Reload config (#2180)

Reload config when restart or reboot emqx
This commit is contained in:
Gilbert 2019-01-24 23:55:57 +08:00 committed by GitHub
parent d5b17c516e
commit b461e26f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -17,7 +17,7 @@
-include("emqx.hrl"). -include("emqx.hrl").
%% Start/Stop the application %% Start/Stop the application
-export([start/0, is_running/1, stop/0]). -export([start/0, restart/1, is_running/1, stop/0]).
%% PubSub API %% PubSub API
-export([subscribe/1, subscribe/2, subscribe/3]). -export([subscribe/1, subscribe/2, subscribe/3]).
@ -47,6 +47,12 @@ start() ->
%% Check Mnesia %% Check Mnesia
application:ensure_all_started(?APP). application:ensure_all_started(?APP).
-spec(restart(string()) -> ok).
restart(ConfFile) ->
reload_config(ConfFile),
shutdown(),
reboot().
%% @doc Stop emqx application. %% @doc Stop emqx application.
-spec(stop() -> ok | {error, term()}). -spec(stop() -> ok | {error, term()}).
stop() -> stop() ->
@ -158,3 +164,11 @@ shutdown(Reason) ->
reboot() -> reboot() ->
lists:foreach(fun application:start/1, [gproc, esockd, ranch, cowboy, ekka, emqx]). lists:foreach(fun application:start/1, [gproc, esockd, ranch, cowboy, ekka, emqx]).
%%------------------------------------------------------------------------------
%% Internal functions
%%------------------------------------------------------------------------------
reload_config(ConfFile) ->
{ok, [Conf]} = file:consult(ConfFile),
lists:foreach(fun({App, Vals}) ->
[application:set_env(App, Par, Val) || {Par, Val} <- Vals]
end, Conf).