From 27c922dbf2cd4abf29ecfbb893f8f54c1999036b Mon Sep 17 00:00:00 2001 From: ieQu1 <99872536+ieQu1@users.noreply.github.com> Date: Tue, 24 May 2022 12:39:37 +0200 Subject: [PATCH] fix(emqx_machine): Start essential applications as permanent --- apps/emqx_machine/src/emqx_machine_boot.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/emqx_machine/src/emqx_machine_boot.erl b/apps/emqx_machine/src/emqx_machine_boot.erl index 638b1488f..dbbf12da4 100644 --- a/apps/emqx_machine/src/emqx_machine_boot.erl +++ b/apps/emqx_machine/src/emqx_machine_boot.erl @@ -29,6 +29,9 @@ %% these apps are always (re)started by emqx_machine -define(BASIC_REBOOT_APPS, [gproc, esockd, ranch, cowboy, emqx]). +%% If any of these applications crash, the entire EMQX node shuts down +-define(BASIC_PERMANENT_APPS, [mria, ekka, esockd, emqx]). + post_boot() -> ok = ensure_apps_started(), ok = print_vsn(), @@ -76,7 +79,7 @@ ensure_apps_started() -> start_one_app(App) -> ?SLOG(debug, #{msg => "starting_app", app => App}), - case application:ensure_all_started(App) of + case application:ensure_all_started(App, restart_type(App)) of {ok, Apps} -> ?SLOG(debug, #{msg => "started_apps", apps => Apps}); {error, Reason} -> @@ -84,6 +87,16 @@ start_one_app(App) -> error({failed_to_start_app, App, Reason}) end. +restart_type(App) -> + PermanentApps = + ?BASIC_PERMANENT_APPS ++ application:get_env(emqx_machine, permanent_applications, []), + case lists:member(App, PermanentApps) of + true -> + permanent; + false -> + temporary + end. + %% list of app names which should be rebooted when: %% 1. due to static config change %% 2. after join a cluster