refactor(emqx_machine): supervise terminator
This commit is contained in:
parent
032a49114c
commit
e698600903
|
@ -24,9 +24,7 @@
|
|||
|
||||
start(_Type, _Args) ->
|
||||
ok = emqx_machine:start(),
|
||||
{ok, Sup} = emqx_machine_sup:start_link(),
|
||||
ok = emqx_machine_terminator:start(),
|
||||
{ok, Sup}.
|
||||
emqx_machine_sup:start_link().
|
||||
|
||||
stop(_State) ->
|
||||
ok.
|
||||
|
|
|
@ -29,18 +29,19 @@ start_link() ->
|
|||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
GlobalGC = child_worker(emqx_global_gc, []),
|
||||
Children = [GlobalGC],
|
||||
SupFlags = #{strategy => one_for_all,
|
||||
GlobalGC = child_worker(emqx_global_gc, [], permanent),
|
||||
Terminator = child_worker(emqx_machine_terminator, [], transient),
|
||||
Children = [GlobalGC, Terminator],
|
||||
SupFlags = #{strategy => one_for_one,
|
||||
intensity => 100,
|
||||
period => 10
|
||||
},
|
||||
{ok, {SupFlags, Children}}.
|
||||
|
||||
child_worker(M, Args) ->
|
||||
child_worker(M, Args, Restart) ->
|
||||
#{id => M,
|
||||
start => {M, start_link, Args},
|
||||
restart => permanent,
|
||||
restart => Restart,
|
||||
shutdown => 5000,
|
||||
type => worker,
|
||||
modules => [M]
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([ start/0
|
||||
-export([ start_link/0
|
||||
, graceful/0
|
||||
, graceful_wait/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.
|
||||
%% 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.
|
||||
start() ->
|
||||
{ok, _} = gen_server:start_link({local, ?TERMINATOR}, ?MODULE, [], []),
|
||||
%% NOTE: Do not link this process under any supervision tree
|
||||
ok.
|
||||
start_link() ->
|
||||
{ok, _} = gen_server:start_link({local, ?TERMINATOR}, ?MODULE, [], []).
|
||||
|
||||
is_running() -> is_pid(whereis(?TERMINATOR)).
|
||||
|
||||
|
|
Loading…
Reference in New Issue