Przeglądaj źródła

fix(emqx_machine): Start essential applications as permanent

ieQu1 3 lat temu
rodzic
commit
27c922dbf2
1 zmienionych plików z 14 dodań i 1 usunięć
  1. 14 1
      apps/emqx_machine/src/emqx_machine_boot.erl

+ 14 - 1
apps/emqx_machine/src/emqx_machine_boot.erl

@@ -29,6 +29,9 @@
 %% these apps are always (re)started by emqx_machine
 %% these apps are always (re)started by emqx_machine
 -define(BASIC_REBOOT_APPS, [gproc, esockd, ranch, cowboy, emqx]).
 -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() ->
 post_boot() ->
     ok = ensure_apps_started(),
     ok = ensure_apps_started(),
     ok = print_vsn(),
     ok = print_vsn(),
@@ -76,7 +79,7 @@ ensure_apps_started() ->
 
 
 start_one_app(App) ->
 start_one_app(App) ->
     ?SLOG(debug, #{msg => "starting_app", 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} ->
         {ok, Apps} ->
             ?SLOG(debug, #{msg => "started_apps", apps => Apps});
             ?SLOG(debug, #{msg => "started_apps", apps => Apps});
         {error, Reason} ->
         {error, Reason} ->
@@ -84,6 +87,16 @@ start_one_app(App) ->
             error({failed_to_start_app, App, Reason})
             error({failed_to_start_app, App, Reason})
     end.
     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:
 %% list of app names which should be rebooted when:
 %% 1. due to static config change
 %% 1. due to static config change
 %% 2. after join a cluster
 %% 2. after join a cluster