refactor(emqx_sup): move global gc to emqx_machine app
This commit is contained in:
parent
522d8e0a4a
commit
5b5006e8ab
|
@ -24,6 +24,7 @@
|
||||||
, get_description/0
|
, get_description/0
|
||||||
, get_release/0
|
, get_release/0
|
||||||
, set_init_config_load_done/0
|
, set_init_config_load_done/0
|
||||||
|
, set_override_conf_file/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
|
@ -70,6 +71,13 @@ stop(_State) -> ok.
|
||||||
set_init_config_load_done() ->
|
set_init_config_load_done() ->
|
||||||
application:set_env(emqx, init_config_load_done, true).
|
application:set_env(emqx, init_config_load_done, true).
|
||||||
|
|
||||||
|
%% @doc This API is mostly for testing.
|
||||||
|
%% The override config file is typically located in the 'data' dir when
|
||||||
|
%% it is a emqx release, but emqx app should not have to konw where the
|
||||||
|
%% 'data' dir is located.
|
||||||
|
set_override_conf_file(File) ->
|
||||||
|
application:set_env(emqx, override_conf_file, File).
|
||||||
|
|
||||||
maybe_load_config() ->
|
maybe_load_config() ->
|
||||||
case application:get_env(emqx, init_config_load_done, false) of
|
case application:get_env(emqx, init_config_load_done, false) of
|
||||||
true ->
|
true ->
|
||||||
|
|
|
@ -260,7 +260,7 @@ load_hocon_file(FileName, LoadType) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
emqx_override_conf_name() ->
|
emqx_override_conf_name() ->
|
||||||
filename:join([?MODULE:get([node, data_dir]), "emqx_override.conf"]).
|
application:get_env(emqx, override_conf_file, "emqx_override.conf").
|
||||||
|
|
||||||
bin(Bin) when is_binary(Bin) -> Bin;
|
bin(Bin) when is_binary(Bin) -> Bin;
|
||||||
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
||||||
|
|
|
@ -29,7 +29,6 @@ init([]) ->
|
||||||
{ok, {{one_for_one, 10, 100},
|
{ok, {{one_for_one, 10, 100},
|
||||||
%% always start emqx_config_handler first to load the emqx.conf to emqx_config
|
%% always start emqx_config_handler first to load the emqx.conf to emqx_config
|
||||||
[ child_spec(emqx_config_handler, worker)
|
[ child_spec(emqx_config_handler, worker)
|
||||||
, child_spec(emqx_global_gc, worker)
|
|
||||||
, child_spec(emqx_pool_sup, supervisor)
|
, child_spec(emqx_pool_sup, supervisor)
|
||||||
, child_spec(emqx_hooks, worker)
|
, child_spec(emqx_hooks, worker)
|
||||||
, child_spec(emqx_stats, worker)
|
, child_spec(emqx_stats, worker)
|
||||||
|
|
|
@ -67,7 +67,7 @@ init([]) ->
|
||||||
BrokerSup = child_spec(emqx_broker_sup, supervisor),
|
BrokerSup = child_spec(emqx_broker_sup, supervisor),
|
||||||
CMSup = child_spec(emqx_cm_sup, supervisor),
|
CMSup = child_spec(emqx_cm_sup, supervisor),
|
||||||
SysSup = child_spec(emqx_sys_sup, supervisor),
|
SysSup = child_spec(emqx_sys_sup, supervisor),
|
||||||
Childs = [KernelSup] ++
|
Children = [KernelSup] ++
|
||||||
[RouterSup || emqx_boot:is_enabled(router)] ++
|
[RouterSup || emqx_boot:is_enabled(router)] ++
|
||||||
[BrokerSup || emqx_boot:is_enabled(broker)] ++
|
[BrokerSup || emqx_boot:is_enabled(broker)] ++
|
||||||
[CMSup || emqx_boot:is_enabled(broker)] ++
|
[CMSup || emqx_boot:is_enabled(broker)] ++
|
||||||
|
@ -76,7 +76,7 @@ init([]) ->
|
||||||
intensity => 0,
|
intensity => 0,
|
||||||
period => 1
|
period => 1
|
||||||
},
|
},
|
||||||
{ok, {SupFlags, Childs}}.
|
{ok, {SupFlags, Children}}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
|
@ -32,13 +32,15 @@ start(_Type, _Args) ->
|
||||||
|
|
||||||
ok = load_config_files(),
|
ok = load_config_files(),
|
||||||
|
|
||||||
|
{ok, RootSupPid} = emqx_machine_sup:start_link(),
|
||||||
|
|
||||||
{ok, _} = application:ensure_all_started(emqx),
|
{ok, _} = application:ensure_all_started(emqx),
|
||||||
|
|
||||||
_ = emqx_plugins:load(),
|
_ = emqx_plugins:load(),
|
||||||
_ = start_modules(),
|
_ = start_modules(),
|
||||||
|
|
||||||
ok = print_vsn(),
|
ok = print_vsn(),
|
||||||
emqx_machine_sup:start_link().
|
{ok, RootSupPid}.
|
||||||
|
|
||||||
prep_stop(_State) ->
|
prep_stop(_State) ->
|
||||||
application:stop(emqx).
|
application:stop(emqx).
|
||||||
|
|
|
@ -128,10 +128,8 @@ fields("node") ->
|
||||||
sensitive => true,
|
sensitive => true,
|
||||||
override_env => "EMQX_NODE_COOKIE"
|
override_env => "EMQX_NODE_COOKIE"
|
||||||
})}
|
})}
|
||||||
, {"data_dir", t(string(), undefined, undefined)}
|
, {"data_dir", hoconsc:t(string(), #{nullable => false})}
|
||||||
, {"config_files", t(list(string()), "emqx.config_files",
|
, {"config_files", t(list(string()), "emqx.config_files", undefined)}
|
||||||
[ filename:join([os:getenv("RUNNER_ETC_DIR"), "emqx.conf"])
|
|
||||||
])}
|
|
||||||
, {"global_gc_interval", t(emqx_schema:duration(), undefined, "15m")}
|
, {"global_gc_interval", t(emqx_schema:duration(), undefined, "15m")}
|
||||||
, {"crash_dump_dir", t(file(), "vm_args.-env ERL_CRASH_DUMP", undefined)}
|
, {"crash_dump_dir", t(file(), "vm_args.-env ERL_CRASH_DUMP", undefined)}
|
||||||
, {"dist_net_ticktime", t(emqx_schema:duration(), "vm_args.-kernel net_ticktime", "2m")}
|
, {"dist_net_ticktime", t(emqx_schema:duration(), "vm_args.-kernel net_ticktime", "2m")}
|
||||||
|
@ -230,6 +228,7 @@ translation("kernel") ->
|
||||||
, {"logger", fun tr_logger/1}];
|
, {"logger", fun tr_logger/1}];
|
||||||
translation("emqx") ->
|
translation("emqx") ->
|
||||||
[ {"config_files", fun tr_config_files/1}
|
[ {"config_files", fun tr_config_files/1}
|
||||||
|
, {"override_conf_file", fun tr_override_conf_fie/1}
|
||||||
].
|
].
|
||||||
|
|
||||||
tr_config_files(Conf) ->
|
tr_config_files(Conf) ->
|
||||||
|
@ -245,6 +244,12 @@ tr_config_files(Conf) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
tr_override_conf_fie(Conf) ->
|
||||||
|
DataDir = conf_get("node.data_dir", Conf),
|
||||||
|
%% assert, this config is not nullable
|
||||||
|
[_ | _] = DataDir,
|
||||||
|
filename:join([DataDir, "emqx_override.conf"]).
|
||||||
|
|
||||||
tr_cluster__discovery(Conf) ->
|
tr_cluster__discovery(Conf) ->
|
||||||
Strategy = conf_get("cluster.discovery_strategy", Conf),
|
Strategy = conf_get("cluster.discovery_strategy", Conf),
|
||||||
{Strategy, filter(options(Strategy, Conf))}.
|
{Strategy, filter(options(Strategy, Conf))}.
|
||||||
|
|
|
@ -27,8 +27,28 @@ start_link() ->
|
||||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||||
|
|
||||||
init([]) ->
|
init([]) ->
|
||||||
|
GlobalGC = child_worker(emqx_global_gc, []),
|
||||||
|
Children = [GlobalGC],
|
||||||
SupFlags = #{strategy => one_for_all,
|
SupFlags = #{strategy => one_for_all,
|
||||||
intensity => 0,
|
intensity => 100,
|
||||||
period => 1
|
period => 10
|
||||||
},
|
},
|
||||||
{ok, {SupFlags, []}}.
|
{ok, {SupFlags, Children}}.
|
||||||
|
|
||||||
|
% child_supervisor(Mod) ->
|
||||||
|
% #{id => Mod,
|
||||||
|
% start => {Mod, start_link, []},
|
||||||
|
% restart => permanent,
|
||||||
|
% shutdown => infinity,
|
||||||
|
% type => supervisor,
|
||||||
|
% modules => [Mod]
|
||||||
|
% }.
|
||||||
|
|
||||||
|
child_worker(M, Args) ->
|
||||||
|
#{id => M,
|
||||||
|
start => {M, start_link, Args},
|
||||||
|
restart => permanent,
|
||||||
|
shutdown => 5000,
|
||||||
|
type => worker,
|
||||||
|
modules => [M]
|
||||||
|
}.
|
||||||
|
|
Loading…
Reference in New Issue