refactor(emqx_app): start quic listener condition

when the app is present, and when listners are configured
This commit is contained in:
Zaiming Shi 2021-08-05 00:08:00 +02:00
parent bdb871cb9a
commit ce24696329
3 changed files with 21 additions and 15 deletions

View File

@ -96,14 +96,23 @@ maybe_start_listeners() ->
end. end.
maybe_start_quicer() -> maybe_start_quicer() ->
case os:getenv("EMQX_NO_QUIC") of case is_quicer_app_present() andalso is_quic_listener_configured() of
X when X =:= "1" orelse X =:= "true" -> true -> {ok, _} = application:ensure_all_started(quicer), ok;
ok; false -> ok
_ ->
{ok, _} = application:ensure_all_started(quicer),
ok
end. end.
is_quicer_app_present() ->
case application:load(quicer) of
ok -> true;
{error, {already_loaded, _}} -> true;
_ ->
?SLOG(info, #{msg => "quicer_app_not_found"}),
false
end.
is_quic_listener_configured() ->
emqx_listeners:has_enabled_listener_conf_by_type(quic).
get_description() -> get_description() ->
{ok, Descr0} = application:get_key(?APP, description), {ok, Descr0} = application:get_key(?APP, description),
case os:getenv("EMQX_DESCRIPTION") of case os:getenv("EMQX_DESCRIPTION") of

View File

@ -34,7 +34,7 @@
, stop_listener/3 , stop_listener/3
, restart_listener/1 , restart_listener/1
, restart_listener/3 , restart_listener/3
, has_listener_conf_by_type/1 , has_enabled_listener_conf_by_type/1
]). ]).
%% @doc List configured listeners. %% @doc List configured listeners.
@ -296,10 +296,11 @@ foreach_listeners(Do) ->
Do(ZoneName, LName, LConf) Do(ZoneName, LName, LConf)
end, do_list()). end, do_list()).
has_listener_conf_by_type(Type) -> has_enabled_listener_conf_by_type(Type) ->
lists:any( lists:any(
fun({_Zone, _LName, LConf}) when is_map(LConf) -> fun({_Zone, _LName, LConf}) when is_map(LConf) ->
Type =:= maps:get(type, LConf) Type =:= maps:get(type, LConf) andalso
maps:get(enabled, LConf, true)
end, do_list()). end, do_list()).
%% merge the configs in zone and listeners in a manner that %% merge the configs in zone and listeners in a manner that

View File

@ -127,15 +127,11 @@ start_one_app(App) ->
%% 1. due to static static config change %% 1. due to static static config change
%% 2. after join a cluster %% 2. after join a cluster
reboot_apps() -> reboot_apps() ->
[gproc, esockd, ranch, cowboy, ekka, quicer, emqx | ?EMQX_DEP_APPS]. [gproc, esockd, ranch, cowboy, ekka, emqx | ?EMQX_DEP_APPS].
%% quicer can not be added to emqx's .app because it might be opted out at build time
implicit_deps() ->
[{emqx, [quicer]}].
sorted_reboot_apps() -> sorted_reboot_apps() ->
Apps = [{App, app_deps(App)} || App <- reboot_apps()], Apps = [{App, app_deps(App)} || App <- reboot_apps()],
sorted_reboot_apps(Apps ++ implicit_deps()). sorted_reboot_apps(Apps).
app_deps(App) -> app_deps(App) ->
case application:get_key(App, applications) of case application:get_key(App, applications) of