fix(emqx_machine): Start essential applications as permanent

This commit is contained in:
ieQu1 2022-05-24 12:39:37 +02:00
parent 9474241ad9
commit 27c922dbf2
1 changed files with 14 additions and 1 deletions

View File

@ -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