diff --git a/apps/emqx_machine/src/emqx_machine_app.erl b/apps/emqx_machine/src/emqx_machine_app.erl index 609df37d1..9a9b13d8f 100644 --- a/apps/emqx_machine/src/emqx_machine_app.erl +++ b/apps/emqx_machine/src/emqx_machine_app.erl @@ -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. diff --git a/apps/emqx_machine/src/emqx_machine_sup.erl b/apps/emqx_machine/src/emqx_machine_sup.erl index 114ed324f..0810eb267 100644 --- a/apps/emqx_machine/src/emqx_machine_sup.erl +++ b/apps/emqx_machine/src/emqx_machine_sup.erl @@ -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] diff --git a/apps/emqx_machine/src/emqx_machine_terminator.erl b/apps/emqx_machine/src/emqx_machine_terminator.erl index 20e818d99..524cf316d 100644 --- a/apps/emqx_machine/src/emqx_machine_terminator.erl +++ b/apps/emqx_machine/src/emqx_machine_terminator.erl @@ -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)).