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_release/0
|
||||
, set_init_config_load_done/0
|
||||
, set_override_conf_file/1
|
||||
]).
|
||||
|
||||
-include("emqx.hrl").
|
||||
|
@ -70,6 +71,13 @@ stop(_State) -> ok.
|
|||
set_init_config_load_done() ->
|
||||
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() ->
|
||||
case application:get_env(emqx, init_config_load_done, false) of
|
||||
true ->
|
||||
|
|
|
@ -260,7 +260,7 @@ load_hocon_file(FileName, LoadType) ->
|
|||
end.
|
||||
|
||||
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(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
||||
|
|
|
@ -29,7 +29,6 @@ init([]) ->
|
|||
{ok, {{one_for_one, 10, 100},
|
||||
%% always start emqx_config_handler first to load the emqx.conf to emqx_config
|
||||
[ child_spec(emqx_config_handler, worker)
|
||||
, child_spec(emqx_global_gc, worker)
|
||||
, child_spec(emqx_pool_sup, supervisor)
|
||||
, child_spec(emqx_hooks, worker)
|
||||
, child_spec(emqx_stats, worker)
|
||||
|
|
|
@ -67,16 +67,16 @@ init([]) ->
|
|||
BrokerSup = child_spec(emqx_broker_sup, supervisor),
|
||||
CMSup = child_spec(emqx_cm_sup, supervisor),
|
||||
SysSup = child_spec(emqx_sys_sup, supervisor),
|
||||
Childs = [KernelSup] ++
|
||||
[RouterSup || emqx_boot:is_enabled(router)] ++
|
||||
[BrokerSup || emqx_boot:is_enabled(broker)] ++
|
||||
[CMSup || emqx_boot:is_enabled(broker)] ++
|
||||
[SysSup],
|
||||
Children = [KernelSup] ++
|
||||
[RouterSup || emqx_boot:is_enabled(router)] ++
|
||||
[BrokerSup || emqx_boot:is_enabled(broker)] ++
|
||||
[CMSup || emqx_boot:is_enabled(broker)] ++
|
||||
[SysSup],
|
||||
SupFlags = #{strategy => one_for_all,
|
||||
intensity => 0,
|
||||
period => 1
|
||||
},
|
||||
{ok, {SupFlags, Childs}}.
|
||||
{ok, {SupFlags, Children}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
|
|
|
@ -32,13 +32,15 @@ start(_Type, _Args) ->
|
|||
|
||||
ok = load_config_files(),
|
||||
|
||||
{ok, RootSupPid} = emqx_machine_sup:start_link(),
|
||||
|
||||
{ok, _} = application:ensure_all_started(emqx),
|
||||
|
||||
_ = emqx_plugins:load(),
|
||||
_ = start_modules(),
|
||||
|
||||
ok = print_vsn(),
|
||||
emqx_machine_sup:start_link().
|
||||
{ok, RootSupPid}.
|
||||
|
||||
prep_stop(_State) ->
|
||||
application:stop(emqx).
|
||||
|
|
|
@ -128,10 +128,8 @@ fields("node") ->
|
|||
sensitive => true,
|
||||
override_env => "EMQX_NODE_COOKIE"
|
||||
})}
|
||||
, {"data_dir", t(string(), undefined, undefined)}
|
||||
, {"config_files", t(list(string()), "emqx.config_files",
|
||||
[ filename:join([os:getenv("RUNNER_ETC_DIR"), "emqx.conf"])
|
||||
])}
|
||||
, {"data_dir", hoconsc:t(string(), #{nullable => false})}
|
||||
, {"config_files", t(list(string()), "emqx.config_files", undefined)}
|
||||
, {"global_gc_interval", t(emqx_schema:duration(), undefined, "15m")}
|
||||
, {"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")}
|
||||
|
@ -230,6 +228,7 @@ translation("kernel") ->
|
|||
, {"logger", fun tr_logger/1}];
|
||||
translation("emqx") ->
|
||||
[ {"config_files", fun tr_config_files/1}
|
||||
, {"override_conf_file", fun tr_override_conf_fie/1}
|
||||
].
|
||||
|
||||
tr_config_files(Conf) ->
|
||||
|
@ -245,6 +244,12 @@ tr_config_files(Conf) ->
|
|||
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) ->
|
||||
Strategy = conf_get("cluster.discovery_strategy", Conf),
|
||||
{Strategy, filter(options(Strategy, Conf))}.
|
||||
|
|
|
@ -27,8 +27,28 @@ start_link() ->
|
|||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
GlobalGC = child_worker(emqx_global_gc, []),
|
||||
Children = [GlobalGC],
|
||||
SupFlags = #{strategy => one_for_all,
|
||||
intensity => 0,
|
||||
period => 1
|
||||
intensity => 100,
|
||||
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