fix(plugins): do not stop Elixir protected apps
On one hand, Elixir plugins might include Elixir itself, when targetting a non-Elixir EMQX release. If, on the other hand, the EMQX release already includes Elixir, we shouldn't stop Elixir nor IEx, or the running IEx shell will break.
This commit is contained in:
parent
eede9f349e
commit
6897f0141b
|
@ -986,14 +986,7 @@ start_app(App) ->
|
||||||
%% but not the ones shared with others.
|
%% but not the ones shared with others.
|
||||||
ensure_apps_stopped(#{<<"rel_apps">> := Apps}) ->
|
ensure_apps_stopped(#{<<"rel_apps">> := Apps}) ->
|
||||||
%% load plugin apps and beam code
|
%% load plugin apps and beam code
|
||||||
AppsToStop =
|
AppsToStop = lists:filtermap(fun parse_name_vsn_for_stopping/1, Apps),
|
||||||
lists:map(
|
|
||||||
fun(NameVsn) ->
|
|
||||||
{ok, AppName, _AppVsn} = parse_name_vsn(NameVsn),
|
|
||||||
AppName
|
|
||||||
end,
|
|
||||||
Apps
|
|
||||||
),
|
|
||||||
case tryit("stop_apps", fun() -> stop_apps(AppsToStop) end) of
|
case tryit("stop_apps", fun() -> stop_apps(AppsToStop) end) of
|
||||||
{ok, []} ->
|
{ok, []} ->
|
||||||
%% all apps stopped
|
%% all apps stopped
|
||||||
|
@ -1009,6 +1002,30 @@ ensure_apps_stopped(#{<<"rel_apps">> := Apps}) ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% On one hand, Elixir plugins might include Elixir itself, when targetting a non-Elixir
|
||||||
|
%% EMQX release. If, on the other hand, the EMQX release already includes Elixir, we
|
||||||
|
%% shouldn't stop Elixir nor IEx.
|
||||||
|
-ifdef(EMQX_ELIXIR).
|
||||||
|
is_protected_app(elixir) -> true;
|
||||||
|
is_protected_app(iex) -> true;
|
||||||
|
is_protected_app(_) -> false.
|
||||||
|
|
||||||
|
parse_name_vsn_for_stopping(NameVsn) ->
|
||||||
|
{ok, AppName, _AppVsn} = parse_name_vsn(NameVsn),
|
||||||
|
case is_protected_app(AppName) of
|
||||||
|
true ->
|
||||||
|
false;
|
||||||
|
false ->
|
||||||
|
{true, AppName}
|
||||||
|
end.
|
||||||
|
%% ELSE ifdef(EMQX_ELIXIR)
|
||||||
|
-else.
|
||||||
|
parse_name_vsn_for_stopping(NameVsn) ->
|
||||||
|
{ok, AppName, _AppVsn} = parse_name_vsn(NameVsn),
|
||||||
|
{true, AppName}.
|
||||||
|
%% END ifdef(EMQX_ELIXIR)
|
||||||
|
-endif.
|
||||||
|
|
||||||
stop_apps(Apps) ->
|
stop_apps(Apps) ->
|
||||||
RunningApps = running_apps(),
|
RunningApps = running_apps(),
|
||||||
case do_stop_apps(Apps, [], RunningApps) of
|
case do_stop_apps(Apps, [], RunningApps) of
|
||||||
|
@ -1045,8 +1062,10 @@ stop_app(App) ->
|
||||||
|
|
||||||
unload_moudle_and_app(App) ->
|
unload_moudle_and_app(App) ->
|
||||||
case application:get_key(App, modules) of
|
case application:get_key(App, modules) of
|
||||||
{ok, Modules} -> lists:foreach(fun code:soft_purge/1, Modules);
|
{ok, Modules} ->
|
||||||
_ -> ok
|
lists:foreach(fun code:soft_purge/1, Modules);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
end,
|
end,
|
||||||
_ = application:unload(App),
|
_ = application:unload(App),
|
||||||
ok.
|
ok.
|
||||||
|
|
1
mix.exs
1
mix.exs
|
@ -270,6 +270,7 @@ defmodule EMQXUmbrella.MixProject do
|
||||||
:debug_info,
|
:debug_info,
|
||||||
{:compile_info, [{:emqx_vsn, String.to_charlist(version)}]},
|
{:compile_info, [{:emqx_vsn, String.to_charlist(version)}]},
|
||||||
{:d, :EMQX_RELEASE_EDITION, erlang_edition(edition_type)},
|
{:d, :EMQX_RELEASE_EDITION, erlang_edition(edition_type)},
|
||||||
|
{:d, :EMQX_ELIXIR},
|
||||||
{:d, :snk_kind, :msg}
|
{:d, :snk_kind, :msg}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue