From 9a6056ff2fb36b71a692a01e68e5feb2185fec48 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 6 Dec 2023 15:18:51 +0100 Subject: [PATCH] refactor(emqx_machine): move system_monitor to included_applications system_monitor has to be found in application (or included_applications) otherwise dialyzer fails with Unknown function Adding to 'applications' would cause a deadlock because one cannot call application:ensure_all_started in the application/2 callback. --- apps/emqx_machine/priv/reboot_lists.eterm | 18 +++++++++--------- apps/emqx_machine/src/emqx_machine.app.src | 8 +++++++- apps/emqx_machine/src/emqx_machine.erl | 2 +- apps/emqx_machine/src/emqx_machine_boot.erl | 5 +---- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/emqx_machine/priv/reboot_lists.eterm b/apps/emqx_machine/priv/reboot_lists.eterm index 6dffd5e2d..cf3ad1523 100644 --- a/apps/emqx_machine/priv/reboot_lists.eterm +++ b/apps/emqx_machine/priv/reboot_lists.eterm @@ -24,8 +24,15 @@ runtime_tools, redbug, xmerl, + %% has no application/2 callback {hocon, load}, - telemetry + telemetry, + observer_cli, + covertool, + tools, + observer, + {system_monitor, load}, + jq ], %% must always be of type `load' common_business_apps => @@ -33,11 +40,6 @@ emqx, emqx_conf, esasl, - observer_cli, - tools, - covertool, - %% started by emqx_machine - system_monitor, emqx_utils, emqx_durable_storage, emqx_http_lib, @@ -79,9 +81,7 @@ emqx_plugins, emqx_opentelemetry, quicer, - bcrypt, - jq, - observer + bcrypt ], %% must always be of type `load' ee_business_apps => diff --git a/apps/emqx_machine/src/emqx_machine.app.src b/apps/emqx_machine/src/emqx_machine.app.src index 904d5fe77..e3b37fc23 100644 --- a/apps/emqx_machine/src/emqx_machine.app.src +++ b/apps/emqx_machine/src/emqx_machine.app.src @@ -6,7 +6,13 @@ {vsn, "0.2.17"}, {modules, []}, {registered, []}, - {applications, [kernel, stdlib, emqx_ctl, system_monitor, covertool]}, + {applications, [kernel, stdlib, emqx_ctl, covertool]}, + %% system_monitor is loaded but not booted, + %% emqx_machine.erl makes the decision when to start + %% the app after certain config injection. + %% it's a included_application because otherwise dialyzer + %% would report unknown functions + {included_applications, [system_monitor]}, {mod, {emqx_machine_app, []}}, {env, []}, {licenses, ["Apache-2.0"]}, diff --git a/apps/emqx_machine/src/emqx_machine.erl b/apps/emqx_machine/src/emqx_machine.erl index 8dc385fb3..fee7fa7aa 100644 --- a/apps/emqx_machine/src/emqx_machine.erl +++ b/apps/emqx_machine/src/emqx_machine.erl @@ -47,7 +47,7 @@ start() -> os:set_signal(sigterm, handle) end, ok = set_backtrace_depth(), - start_sysmon(), + ok = start_sysmon(), configure_shard_transports(), set_mnesia_extra_diagnostic_checks(), emqx_otel_app:configure_otel_deps(), diff --git a/apps/emqx_machine/src/emqx_machine_boot.erl b/apps/emqx_machine/src/emqx_machine_boot.erl index afb195543..08cf8c448 100644 --- a/apps/emqx_machine/src/emqx_machine_boot.erl +++ b/apps/emqx_machine/src/emqx_machine_boot.erl @@ -36,9 +36,6 @@ %% If any of these applications crash, the entire EMQX node shuts down: -define(BASIC_PERMANENT_APPS, [mria, ekka, esockd, emqx]). -%% These apps should NOT be (re)started automatically: --define(EXCLUDED_APPS, [system_monitor, observer_cli, jq]). - %% These apps are optional, they may or may not be present in the %% release, depending on the build flags: -define(OPTIONAL_APPS, [bcrypt, observer]). @@ -157,7 +154,7 @@ basic_reboot_apps() -> excluded_apps() -> %% Optional apps _should_ be (re)started automatically, but only %% when they are found in the release: - ?EXCLUDED_APPS ++ [App || App <- ?OPTIONAL_APPS, not is_app(App)]. + [App || App <- ?OPTIONAL_APPS, not is_app(App)]. is_app(Name) -> case application:load(Name) of