diff --git a/src/emqx_app.erl b/src/emqx_app.erl index 29b8d9b49..8eacdca48 100644 --- a/src/emqx_app.erl +++ b/src/emqx_app.erl @@ -35,10 +35,10 @@ start(_Type, _Args) -> ok = emqx_modules:load(), ok = emqx_plugins:init(), emqx_plugins:load(), - ok = emqx_listeners:start(), + emqx_boot:is_enabled(listeners) + andalso (ok = emqx_listeners:start()), start_autocluster(), register(emqx, self()), - emqx_alarm_handler:load(), print_vsn(), {ok, Sup}. @@ -46,7 +46,8 @@ start(_Type, _Args) -> -spec(stop(State :: term()) -> term()). stop(_State) -> emqx_alarm_handler:unload(), - emqx_listeners:stop(), + emqx_boot:is_enabled(listeners) + andalso emqx_listeners:stop(), emqx_modules:unload(). %%-------------------------------------------------------------------- diff --git a/src/emqx_boot.erl b/src/emqx_boot.erl new file mode 100644 index 000000000..aa89449cc --- /dev/null +++ b/src/emqx_boot.erl @@ -0,0 +1,29 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-module(emqx_boot). + +-export([is_enabled/1]). + +-define(BOOT_MODULES, [router, broker, listeners]). + +-spec(is_enabled(all|list(router|broker|listeners)) -> boolean()). +is_enabled(Mod) -> + (BootMods = boot_modules()) =:= all orelse lists:member(Mod, BootMods). + +boot_modules() -> + application:get_env(emqx, boot_modules, ?BOOT_MODULES). + diff --git a/src/emqx_sup.erl b/src/emqx_sup.erl index d3a81fc7f..f95e79b6d 100644 --- a/src/emqx_sup.erl +++ b/src/emqx_sup.erl @@ -62,18 +62,21 @@ stop_child(ChildId) -> %%-------------------------------------------------------------------- init([]) -> - %% Kernel Sup KernelSup = child_spec(emqx_kernel_sup, supervisor), - %% Router Sup RouterSup = child_spec(emqx_router_sup, supervisor), - %% Broker Sup BrokerSup = child_spec(emqx_broker_sup, supervisor), - %% CM Sup CMSup = child_spec(emqx_cm_sup, supervisor), - %% Sys Sup SysSup = child_spec(emqx_sys_sup, supervisor), - {ok, {{one_for_all, 0, 1}, - [KernelSup, RouterSup, BrokerSup, CMSup, SysSup]}}. + Childs = [KernelSup] ++ + [RouterSup || emqx_boot:is_enabled(router)] ++ + [BrokerSup || emqx_boot:is_enabled(broker)] ++ + [CMSup || emqx_boot:is_enabled(broker)] ++ + [SysSup], + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1 + }, + {ok, {SupFlags, Childs}}. %%-------------------------------------------------------------------- %% Internal functions diff --git a/test/emqx_access_SUITE.erl b/test/emqx_access_SUITE.erl index c98973d22..f276e4929 100644 --- a/test/emqx_access_SUITE.erl +++ b/test/emqx_access_SUITE.erl @@ -63,6 +63,7 @@ groups() -> }]. init_per_suite(Config) -> + emqx_ct_helpers:boot_modules([router, broker]), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_alarm_handler_SUITE.erl b/test/emqx_alarm_handler_SUITE.erl index 6dd367b4a..3e818f007 100644 --- a/test/emqx_alarm_handler_SUITE.erl +++ b/test/emqx_alarm_handler_SUITE.erl @@ -26,6 +26,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([], fun set_special_configs/1), Config. diff --git a/test/emqx_boot_SUITE.erl b/test/emqx_boot_SUITE.erl new file mode 100644 index 000000000..c4a9ffc39 --- /dev/null +++ b/test/emqx_boot_SUITE.erl @@ -0,0 +1,43 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-module(emqx_boot_SUITE). + +-compile(export_all). +-compile(nowarn_export_all). + +-include_lib("eunit/include/eunit.hrl"). + +all() -> emqx_ct:all(?MODULE). + +t_is_enabled(_) -> + ok = application:set_env(emqx, boot_modules, all), + ?assert(emqx_boot:is_enabled(router)), + ?assert(emqx_boot:is_enabled(broker)), + ?assert(emqx_boot:is_enabled(listeners)), + ok = application:set_env(emqx, boot_modules, [router]), + ?assert(emqx_boot:is_enabled(router)), + ?assertNot(emqx_boot:is_enabled(broker)), + ?assertNot(emqx_boot:is_enabled(listeners)), + ok = application:set_env(emqx, boot_modules, [router, broker]), + ?assert(emqx_boot:is_enabled(router)), + ?assert(emqx_boot:is_enabled(broker)), + ?assertNot(emqx_boot:is_enabled(listeners)), + ok = application:set_env(emqx, boot_modules, [router, broker, listeners]), + ?assert(emqx_boot:is_enabled(router)), + ?assert(emqx_boot:is_enabled(broker)), + ?assert(emqx_boot:is_enabled(listeners)). + diff --git a/test/emqx_broker_SUITE.erl b/test/emqx_broker_SUITE.erl index 89832e2de..9d6372366 100644 --- a/test/emqx_broker_SUITE.erl +++ b/test/emqx_broker_SUITE.erl @@ -49,6 +49,7 @@ groups() -> }]. init_per_suite(Config) -> + emqx_ct_helpers:boot_modules([router, broker]), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_channel_SUITE.erl b/test/emqx_channel_SUITE.erl index b06bc0b97..187d2e302 100644 --- a/test/emqx_channel_SUITE.erl +++ b/test/emqx_channel_SUITE.erl @@ -31,6 +31,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules([router, broker]), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_client_SUITE.erl b/test/emqx_client_SUITE.erl index 660892112..859406dd8 100644 --- a/test/emqx_client_SUITE.erl +++ b/test/emqx_client_SUITE.erl @@ -70,6 +70,7 @@ groups() -> ]. init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_connection_SUITE.erl b/test/emqx_connection_SUITE.erl index 8e595b8b2..d321d2c85 100644 --- a/test/emqx_connection_SUITE.erl +++ b/test/emqx_connection_SUITE.erl @@ -24,6 +24,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_ctl_SUITE.erl b/test/emqx_ctl_SUITE.erl index b4c3d953d..5e18f19c2 100644 --- a/test/emqx_ctl_SUITE.erl +++ b/test/emqx_ctl_SUITE.erl @@ -25,6 +25,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules([]), emqx_ct_helpers:start_apps([]), Config. @@ -51,4 +52,3 @@ test(_) -> io:format("Hello world"). - diff --git a/test/emqx_mod_subscription_SUITE.erl b/test/emqx_mod_subscription_SUITE.erl index 464bfcc76..0c9c9c678 100644 --- a/test/emqx_mod_subscription_SUITE.erl +++ b/test/emqx_mod_subscription_SUITE.erl @@ -28,6 +28,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([emqx]), Config. diff --git a/test/emqx_plugins_SUITE.erl b/test/emqx_plugins_SUITE.erl index 5cab5b362..793e506a3 100644 --- a/test/emqx_plugins_SUITE.erl +++ b/test/emqx_plugins_SUITE.erl @@ -37,6 +37,7 @@ init_per_suite(Config) -> code:add_path(filename:join([AppPath, "_build", "default", "lib", "emqx_mini_plugin", "ebin"])), put(loaded_file, filename:join([DataPath, "loaded_plugins"])), + emqx_ct_helpers:boot_modules([]), emqx_ct_helpers:start_apps([], fun set_sepecial_cfg/1), Config. diff --git a/test/emqx_request_responser_SUITE.erl b/test/emqx_request_responser_SUITE.erl index 4912f72ea..d603f2b96 100644 --- a/test/emqx_request_responser_SUITE.erl +++ b/test/emqx_request_responser_SUITE.erl @@ -22,6 +22,7 @@ -include_lib("common_test/include/ct.hrl"). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_router_SUITE.erl b/test/emqx_router_SUITE.erl index 711f1b1f9..511b62c8b 100644 --- a/test/emqx_router_SUITE.erl +++ b/test/emqx_router_SUITE.erl @@ -27,6 +27,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules([router]), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_shared_sub_SUITE.erl b/test/emqx_shared_sub_SUITE.erl index 1834fdbaf..14baf8a76 100644 --- a/test/emqx_shared_sub_SUITE.erl +++ b/test/emqx_shared_sub_SUITE.erl @@ -32,6 +32,7 @@ all() -> emqx_ct:all(?SUITE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_sys_mon_SUITE.erl b/test/emqx_sys_mon_SUITE.erl index 7f9025b58..b64181fa3 100644 --- a/test/emqx_sys_mon_SUITE.erl +++ b/test/emqx_sys_mon_SUITE.erl @@ -42,6 +42,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_tracer_SUITE.erl b/test/emqx_tracer_SUITE.erl index 684f17e7f..1d9afe028 100644 --- a/test/emqx_tracer_SUITE.erl +++ b/test/emqx_tracer_SUITE.erl @@ -26,6 +26,7 @@ all() -> [t_start_traces]. init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config. diff --git a/test/emqx_ws_connection_SUITE.erl b/test/emqx_ws_connection_SUITE.erl index dfb348253..51b9fde8d 100644 --- a/test/emqx_ws_connection_SUITE.erl +++ b/test/emqx_ws_connection_SUITE.erl @@ -24,6 +24,7 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> + emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), Config.