From b461e26f252e685bfa8fe6a23cd734bd55b53869 Mon Sep 17 00:00:00 2001 From: Gilbert Date: Thu, 24 Jan 2019 23:55:57 +0800 Subject: [PATCH] Reload config (#2180) Reload config when restart or reboot emqx --- src/emqx.erl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/emqx.erl b/src/emqx.erl index 76e966a59..728b35cfc 100644 --- a/src/emqx.erl +++ b/src/emqx.erl @@ -17,7 +17,7 @@ -include("emqx.hrl"). %% Start/Stop the application --export([start/0, is_running/1, stop/0]). +-export([start/0, restart/1, is_running/1, stop/0]). %% PubSub API -export([subscribe/1, subscribe/2, subscribe/3]). @@ -47,6 +47,12 @@ start() -> %% Check Mnesia application:ensure_all_started(?APP). +-spec(restart(string()) -> ok). +restart(ConfFile) -> + reload_config(ConfFile), + shutdown(), + reboot(). + %% @doc Stop emqx application. -spec(stop() -> ok | {error, term()}). stop() -> @@ -158,3 +164,11 @@ shutdown(Reason) -> reboot() -> 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).