refactor(emqx_machine): supervise terminator

This commit is contained in:
Zaiming Shi 2021-08-06 12:51:25 +02:00
parent 032a49114c
commit e698600903
3 changed files with 10 additions and 13 deletions

View File

@ -24,9 +24,7 @@
start(_Type, _Args) -> start(_Type, _Args) ->
ok = emqx_machine:start(), ok = emqx_machine:start(),
{ok, Sup} = emqx_machine_sup:start_link(), emqx_machine_sup:start_link().
ok = emqx_machine_terminator:start(),
{ok, Sup}.
stop(_State) -> stop(_State) ->
ok. ok.

View File

@ -29,18 +29,19 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []). supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) -> init([]) ->
GlobalGC = child_worker(emqx_global_gc, []), GlobalGC = child_worker(emqx_global_gc, [], permanent),
Children = [GlobalGC], Terminator = child_worker(emqx_machine_terminator, [], transient),
SupFlags = #{strategy => one_for_all, Children = [GlobalGC, Terminator],
SupFlags = #{strategy => one_for_one,
intensity => 100, intensity => 100,
period => 10 period => 10
}, },
{ok, {SupFlags, Children}}. {ok, {SupFlags, Children}}.
child_worker(M, Args) -> child_worker(M, Args, Restart) ->
#{id => M, #{id => M,
start => {M, start_link, Args}, start => {M, start_link, Args},
restart => permanent, restart => Restart,
shutdown => 5000, shutdown => 5000,
type => worker, type => worker,
modules => [M] modules => [M]

View File

@ -18,7 +18,7 @@
-behaviour(gen_server). -behaviour(gen_server).
-export([ start/0 -export([ start_link/0
, graceful/0 , graceful/0
, graceful_wait/0 , graceful_wait/0
, is_running/0 , is_running/0
@ -36,10 +36,8 @@
%% @doc This API is called to shutdown the Erlang VM by RPC call from remote shell node. %% @doc This API is called to shutdown the Erlang VM by RPC call from remote shell node.
%% The shutown of apps is delegated to a to a process instead of doing it in the RPC spawned %% The shutown of apps is delegated to a to a process instead of doing it in the RPC spawned
%% process which has a remote group leader. %% process which has a remote group leader.
start() -> start_link() ->
{ok, _} = gen_server:start_link({local, ?TERMINATOR}, ?MODULE, [], []), {ok, _} = gen_server:start_link({local, ?TERMINATOR}, ?MODULE, [], []).
%% NOTE: Do not link this process under any supervision tree
ok.
is_running() -> is_pid(whereis(?TERMINATOR)). is_running() -> is_pid(whereis(?TERMINATOR)).