diff --git a/.github/workflows/elixir_apps_check.yaml b/.github/workflows/elixir_apps_check.yaml index d53271e70..34fff4c49 100644 --- a/.github/workflows/elixir_apps_check.yaml +++ b/.github/workflows/elixir_apps_check.yaml @@ -40,6 +40,8 @@ jobs: run: ./scripts/ensure-rebar3.sh 3.16.1-emqx-1 - name: check applications run: ./scripts/check-elixir-applications.exs + - name: check applications started with emqx_machine + run: ./scripts/check-elixir-emqx-machine-boot-discrepancies.exs env: EMQX_RELEASE_TYPE: ${{ matrix.release_type }} EMQX_PACKAGE_TYPE: ${{ matrix.package_type }} diff --git a/apps/emqx/priv/bpapi.versions b/apps/emqx/priv/bpapi.versions index 362ddd6c4..6b1926b30 100644 --- a/apps/emqx/priv/bpapi.versions +++ b/apps/emqx/priv/bpapi.versions @@ -6,6 +6,7 @@ {emqx_dashboard,1}. {emqx_exhook,1}. {emqx_gateway_cm,1}. +{emqx_license,1}. {emqx_management,1}. {emqx_mgmt_trace,1}. {emqx_persistent_session,1}. diff --git a/apps/emqx/test/emqx_static_checks.erl b/apps/emqx/test/emqx_static_checks.erl index 3cf4d5eb5..aaa7963ef 100644 --- a/apps/emqx/test/emqx_static_checks.erl +++ b/apps/emqx/test/emqx_static_checks.erl @@ -32,12 +32,17 @@ end_per_suite(_Config) -> "If this test suite failed, and you are unsure why, read this:~n" "https://github.com/emqx/emqx/blob/master/apps/emqx/src/bpapi/README.md", []). +check_if_versions_consistent(OldData, NewData) -> + %% OldData can contain a wider list of BPAPI versions + %% than the release being checked. + [] =:= NewData -- OldData. + t_run_check(_) -> try {ok, OldData} = file:consult(emqx_bpapi_static_checks:versions_file()), ?assert(emqx_bpapi_static_checks:run()), {ok, NewData} = file:consult(emqx_bpapi_static_checks:versions_file()), - OldData =:= NewData orelse + check_if_versions_consistent(OldData, NewData) orelse begin logger:critical( "BPAPI versions were changed, but not committed to the repo.\n" diff --git a/apps/emqx_conf/etc/emqx_conf.conf b/apps/emqx_conf/etc/emqx_conf.conf index 18af3cad0..5aff85b86 100644 --- a/apps/emqx_conf/etc/emqx_conf.conf +++ b/apps/emqx_conf/etc/emqx_conf.conf @@ -113,6 +113,14 @@ node { ## Default: 23 backtrace_depth = 23 + ## Comma-separated list of applications to start with emqx_machine. + ## These applications may restart on cluster leave/join. + ## + ## @doc node.applications + ## ValueType: String + ## Default: "gproc, esockd, ranch, cowboy, emqx" + applications = "{{ emqx_machine_boot_apps }}" + cluster_call { retry_interval = 1s max_history = 100 diff --git a/apps/emqx_conf/src/emqx_conf_app.erl b/apps/emqx_conf/src/emqx_conf_app.erl index 2d29285bc..38393b8a4 100644 --- a/apps/emqx_conf/src/emqx_conf_app.erl +++ b/apps/emqx_conf/src/emqx_conf_app.erl @@ -35,9 +35,15 @@ stop(_State) -> init_conf() -> {ok, TnxId} = copy_override_conf_from_core_node(), emqx_app:set_init_tnx_id(TnxId), - emqx_config:init_load(emqx_conf_schema), + emqx_config:init_load(schema_module()), emqx_app:set_init_config_load_done(). +schema_module() -> + case os:getenv("SCHEMA_MOD") of + false -> emqx_conf_schema; + Value -> list_to_existing_atom(Value) + end. + copy_override_conf_from_core_node() -> case nodes() of [] -> %% The first core nodes is self. diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index e63745402..2208879c0 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -306,6 +306,11 @@ a crash dump #{ mapping => "emqx_machine.backtrace_depth" , default => 23 })} + , {"applications", + sc(emqx_schema:comma_separated_atoms(), + #{ mapping => "emqx_machine.applications" + , default => [] + })} , {"etc_dir", sc(string(), #{ desc => "`etc` dir for the node" diff --git a/apps/emqx_machine/src/emqx_machine_boot.erl b/apps/emqx_machine/src/emqx_machine_boot.erl index 89516b76e..d6481ddbf 100644 --- a/apps/emqx_machine/src/emqx_machine_boot.erl +++ b/apps/emqx_machine/src/emqx_machine_boot.erl @@ -26,6 +26,9 @@ -export([sorted_reboot_apps/1]). -endif. +%% these apps are always (re)started by emqx_machine +-define(BASIC_REBOOT_APPS, [gproc, esockd, ranch, cowboy, emqx]). + post_boot() -> ok = ensure_apps_started(), ok = print_vsn(), @@ -80,29 +83,12 @@ start_one_app(App) -> %% list of app names which should be rebooted when: %% 1. due to static config change %% 2. after join a cluster + +%% the list of (re)started apps depends on release type/edition +%% and is configured in rebar.config.erl/mix.exs reboot_apps() -> - [ gproc - , esockd - , ranch - , cowboy - , emqx - , emqx_prometheus - , emqx_modules - , emqx_dashboard - , emqx_connector - , emqx_gateway - , emqx_statsd - , emqx_resource - , emqx_rule_engine - , emqx_bridge - , emqx_plugin_libs - , emqx_management - , emqx_retainer - , emqx_exhook - , emqx_authn - , emqx_authz - , emqx_plugins - ]. + {ok, Apps} = application:get_env(emqx_machine, applications), + ?BASIC_REBOOT_APPS ++ Apps. sorted_reboot_apps() -> Apps = [{App, app_deps(App)} || App <- reboot_apps()], diff --git a/apps/emqx_machine/test/emqx_machine_SUITE.erl b/apps/emqx_machine/test/emqx_machine_SUITE.erl index 6887f1e59..800aa221b 100644 --- a/apps/emqx_machine/test/emqx_machine_SUITE.erl +++ b/apps/emqx_machine/test/emqx_machine_SUITE.erl @@ -42,8 +42,24 @@ init_per_suite(Config) -> %% Unload emqx_authz to avoid reboot this application %% application:unload(emqx_authz), - emqx_common_test_helpers:start_apps([emqx_conf]), + application:set_env(emqx_machine, applications, [ emqx_prometheus + , emqx_modules + , emqx_dashboard + , emqx_connector + , emqx_gateway + , emqx_statsd + , emqx_resource + , emqx_rule_engine + , emqx_bridge + , emqx_plugin_libs + , emqx_management + , emqx_retainer + , emqx_exhook + , emqx_authn + , emqx_authz + , emqx_plugin + ]), Config. end_per_suite(_Config) -> diff --git a/bin/emqx b/bin/emqx index 4e860d97d..5f9d0fdc6 100755 --- a/bin/emqx +++ b/bin/emqx @@ -17,11 +17,11 @@ ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" export RUNNER_ROOT_DIR export RUNNER_ETC_DIR export REL_VSN +export SCHEMA_MOD RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME" CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}" REL_DIR="$RUNNER_ROOT_DIR/releases/$REL_VSN" -SCHEMA_MOD=emqx_conf_schema WHOAMI=$(whoami) @@ -389,7 +389,7 @@ generate_config() { ## meaning, certain overrides will not be mapped to app.