From 044e0846983a2cb430699431fe631795a3fdd361 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Fri, 6 Aug 2021 08:21:38 +0200 Subject: [PATCH] feat(emqx_machine): ignore sighup, ensure sigterm --- apps/emqx_machine/src/emqx_machine.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/emqx_machine/src/emqx_machine.erl b/apps/emqx_machine/src/emqx_machine.erl index 0c077816c..69a0fc05e 100644 --- a/apps/emqx_machine/src/emqx_machine.erl +++ b/apps/emqx_machine/src/emqx_machine.erl @@ -30,6 +30,8 @@ %% @doc EMQ X boot entrypoint. start() -> + os:set_signal(sighup, ignore), + os:set_signal(sigterm, handle), %% default is handle ok = set_backtrace_depth(), ok = print_otp_version_warning(), @@ -101,7 +103,16 @@ stop_apps(Reason) -> stop_one_app(App) -> ?SLOG(debug, #{msg => "stopping_app", app => App}), - application:stop(App). + try + _ = application:stop(App) + catch + C : E -> + ?SLOG(error, #{msg => "failed_to_stop_app", + app => App, + exception => C, + reason => E}) + end. + ensure_apps_started() -> lists:foreach(fun start_one_app/1, sorted_reboot_apps()). @@ -110,7 +121,7 @@ start_one_app(App) -> ?SLOG(debug, #{msg => "starting_app", app => App}), case application:ensure_all_started(App) of {ok, Apps} -> - ?SLOG(debug, #{msg => "started_apps", apps => [App | Apps]}); + ?SLOG(debug, #{msg => "started_apps", apps => Apps}); {error, Reason} -> ?SLOG(critical, #{msg => "failed_to_start_app", app => App, reason => Reason}), error({faile_to_start_app, App, Reason})