From 2d25e895a80423614896901f858afd4a50c378a1 Mon Sep 17 00:00:00 2001 From: x1001100011 Date: Tue, 12 Oct 2021 00:00:57 -0700 Subject: [PATCH] feat: fix applications start order issue --- apps/emqx/mix.exs | 2 +- apps/emqx/src/emqx_app.erl | 4 -- apps/emqx_auto_subscribe/mix.exs | 2 +- apps/emqx_bridge/mix.exs | 4 +- apps/emqx_bridge_mqtt/.formatter.exs | 4 -- apps/emqx_bridge_mqtt/mix.exs | 33 --------- apps/emqx_connector/mix.exs | 3 +- apps/emqx_dashboard/mix.exs | 2 +- apps/emqx_data_bridge/.formatter.exs | 4 -- apps/emqx_data_bridge/mix.exs | 28 -------- apps/emqx_gateway/mix.exs | 2 +- apps/emqx_machine/etc/emqx_machine.conf | 2 +- apps/emqx_psk/mix.exs | 9 ++- .../lib/emqx_release_helper/applications.ex | 67 +++++++++++-------- .../emqx_release_helper/dsl/application.ex | 32 --------- mix.lock | 3 +- rel/overlays/bin/emqx | 12 ++-- 17 files changed, 60 insertions(+), 153 deletions(-) delete mode 100644 apps/emqx_bridge_mqtt/.formatter.exs delete mode 100644 apps/emqx_bridge_mqtt/mix.exs delete mode 100644 apps/emqx_data_bridge/.formatter.exs delete mode 100644 apps/emqx_data_bridge/mix.exs diff --git a/apps/emqx/mix.exs b/apps/emqx/mix.exs index 36c24a310..6651c6cc4 100644 --- a/apps/emqx/mix.exs +++ b/apps/emqx/mix.exs @@ -19,7 +19,7 @@ defmodule EMQX.MixProject do def application do [ mod: {:emqx_app, []}, - extra_applications: [:logger, :os_mon, :syntax_tools, :mnesia] + extra_applications: [:logger, :os_mon, :syntax_tools] ] end diff --git a/apps/emqx/src/emqx_app.erl b/apps/emqx/src/emqx_app.erl index 2d667b805..cd435b864 100644 --- a/apps/emqx/src/emqx_app.erl +++ b/apps/emqx/src/emqx_app.erl @@ -40,10 +40,6 @@ start(_Type, _Args) -> ok = maybe_load_config(), - - %% Load application first for ekka_mnesia scanner - %% mnesia:change_table_copy_type(schema, node(), disc_copies), - ok = maybe_start_quicer(), ensure_ekka_started(), {ok, Sup} = emqx_sup:start_link(), diff --git a/apps/emqx_auto_subscribe/mix.exs b/apps/emqx_auto_subscribe/mix.exs index 7fe4f4a4e..6d1728a71 100644 --- a/apps/emqx_auto_subscribe/mix.exs +++ b/apps/emqx_auto_subscribe/mix.exs @@ -26,7 +26,7 @@ defmodule EMQXAutoSubscribe.MixProject do defp deps do [ - {:emqx, in_umbrella: true} + {:emqx, in_umbrella: true, runtime: false} ] end end diff --git a/apps/emqx_bridge/mix.exs b/apps/emqx_bridge/mix.exs index 09640e0a4..7367a125c 100644 --- a/apps/emqx_bridge/mix.exs +++ b/apps/emqx_bridge/mix.exs @@ -26,8 +26,8 @@ defmodule EMQXBridge.MixProject do defp deps do [ - {:emqx, in_umbrella: true}, - {:emqx_connector, in_umbrella: true} + {:emqx, in_umbrella: true, runtime: false}, + {:emqx_connector, in_umbrella: true} ] end end diff --git a/apps/emqx_bridge_mqtt/.formatter.exs b/apps/emqx_bridge_mqtt/.formatter.exs deleted file mode 100644 index d2cda26ed..000000000 --- a/apps/emqx_bridge_mqtt/.formatter.exs +++ /dev/null @@ -1,4 +0,0 @@ -# Used by "mix format" -[ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] -] diff --git a/apps/emqx_bridge_mqtt/mix.exs b/apps/emqx_bridge_mqtt/mix.exs deleted file mode 100644 index 05a8e0683..000000000 --- a/apps/emqx_bridge_mqtt/mix.exs +++ /dev/null @@ -1,33 +0,0 @@ -defmodule EMQXBridgeMqtt.MixProject do - use Mix.Project - - def project do - [ - app: :emqx_bridge_mqtt, - version: "4.3.1", - build_path: "../../_build", - config_path: "../../config/config.exs", - deps_path: "../../deps", - lockfile: "../../mix.lock", - elixir: "~> 1.12", - start_permanent: Mix.env() == :prod, - deps: deps(), - description: "EMQ X Bridge to MQTT Broker" - ] - end - - def application do - [ - mod: {:emqx_bridge_mqtt_app, []}, - extra_applications: [:logger] - ] - end - - defp deps do - [ - {:emqx, in_umbrella: true, override: true, runtime: false}, - {:emqx_rule_engine, in_umbrella: true}, - {:emqtt, github: "emqx/emqtt", tag: "v1.2.3"} - ] - end -end diff --git a/apps/emqx_connector/mix.exs b/apps/emqx_connector/mix.exs index b0903d6a2..ebe2322e6 100644 --- a/apps/emqx_connector/mix.exs +++ b/apps/emqx_connector/mix.exs @@ -24,9 +24,10 @@ defmodule EMQXConnector.MixProject do defp deps do [ + {:emqx_resource, in_umbrella: true}, {:mysql, github: "emqx/mysql-otp", tag: "1.7.1"}, {:ecpool, github: "emqx/ecpool", tag: "0.5.1"}, - {:emqx_resource, in_umbrella: true} + {:emqtt, github: "emqx/emqtt", tag: "1.4.3"} ] end end diff --git a/apps/emqx_dashboard/mix.exs b/apps/emqx_dashboard/mix.exs index 767645587..b854b1d7c 100644 --- a/apps/emqx_dashboard/mix.exs +++ b/apps/emqx_dashboard/mix.exs @@ -20,7 +20,7 @@ defmodule EMQXDashboard.MixProject do [ registered: [:emqx_dashboard_sup], mod: {:emqx_dashboard_app, []}, - extra_applications: [:logger, :mnesia] + extra_applications: [:logger] ] end diff --git a/apps/emqx_data_bridge/.formatter.exs b/apps/emqx_data_bridge/.formatter.exs deleted file mode 100644 index d2cda26ed..000000000 --- a/apps/emqx_data_bridge/.formatter.exs +++ /dev/null @@ -1,4 +0,0 @@ -# Used by "mix format" -[ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] -] diff --git a/apps/emqx_data_bridge/mix.exs b/apps/emqx_data_bridge/mix.exs deleted file mode 100644 index d4048578f..000000000 --- a/apps/emqx_data_bridge/mix.exs +++ /dev/null @@ -1,28 +0,0 @@ -defmodule EMQXDataBridge.MixProject do - use Mix.Project - - def project do - [ - app: :emqx_data_bridge, - version: "0.1.0", - build_path: "../../_build", - config_path: "../../config/config.exs", - deps_path: "../../deps", - lockfile: "../../mix.lock", - elixir: "~> 1.12", - start_permanent: Mix.env() == :prod, - deps: deps() - ] - end - - def application do - [ - mod: {:emqx_data_bridge_app, []}, - extra_applications: [:logger] - ] - end - - defp deps do - [] - end -end diff --git a/apps/emqx_gateway/mix.exs b/apps/emqx_gateway/mix.exs index b6e042b42..4306cd2f6 100644 --- a/apps/emqx_gateway/mix.exs +++ b/apps/emqx_gateway/mix.exs @@ -26,7 +26,7 @@ defmodule EMQXGateway.MixProject do defp deps do [ - {:emqx, in_umbrella: true, runtime: false}, + {:emqx, in_umbrella: true}, {:lwm2m_coap, github: "emqx/lwm2m-coap", tag: "v2.0.0"}, {:grpc, github: "emqx/grpc-erl", tag: "0.6.2"}, {:esockd, github: "emqx/esockd", tag: "5.7.4"} diff --git a/apps/emqx_machine/etc/emqx_machine.conf b/apps/emqx_machine/etc/emqx_machine.conf index eeab91154..e19c2387e 100644 --- a/apps/emqx_machine/etc/emqx_machine.conf +++ b/apps/emqx_machine/etc/emqx_machine.conf @@ -355,7 +355,7 @@ log { ## @doc log.console_handler..level ## ValueType: debug | info | notice | warning | error | critical | alert | emergency ## Default: warning - level = warning + level = debug ## Timezone offset to display in logs ## diff --git a/apps/emqx_psk/mix.exs b/apps/emqx_psk/mix.exs index 2472b4a31..3e3230646 100644 --- a/apps/emqx_psk/mix.exs +++ b/apps/emqx_psk/mix.exs @@ -1,9 +1,9 @@ -defmodule EmqxRuleActions.MixProject do +defmodule EmqxPSK.MixProject do use Mix.Project def project do [ - app: :emqx_rule_actions, + app: :emqx_psk, version: "5.0.0", build_path: "../../_build", config_path: "../../config/config.exs", @@ -12,7 +12,7 @@ defmodule EmqxRuleActions.MixProject do elixir: "~> 1.12", start_permanent: Mix.env() == :prod, deps: deps(), - description: "Rule Actions" + description: "EMQ X PSK" ] end @@ -26,8 +26,7 @@ defmodule EmqxRuleActions.MixProject do defp deps do [ - {:emqx, in_umbrella: true, runtime: false}, - {:emqx_rule_engine, in_umbrella: true} + {:emqx, in_umbrella: true, runtime: false} ] end end diff --git a/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex b/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex index d80bcb043..d17eb6df8 100644 --- a/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex +++ b/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex @@ -2,7 +2,7 @@ defmodule EmqxReleaseHelper.Applications do use EmqxReleaseHelper.DSL.Application application :emqx do - start_type :permanent + start_type :load overlay %{release_type: release_type} do copy "etc/certs", "etc/certs" @@ -21,19 +21,19 @@ defmodule EmqxReleaseHelper.Applications do end application :emqx_bridge do - start_type :permanent + start_type :load end application :emqx_auto_subscribe do - start_type :permanent + start_type :load end application :emqx_exhook do - start_type :permanent + start_type :load end application :emqx_gateway do - start_type :permanent + start_type :load overlay do copy "src/lwm2m/lwm2m_xml", "etc/lwm2m_xml" @@ -41,29 +41,27 @@ defmodule EmqxReleaseHelper.Applications do end application :emqx_connector do - start_type :permanent + start_type :load end application :emqx_modules do - start_type :permanent + start_type :load end application :emqx_resource do - start_type :permanent + start_type :load end application :emqx_plugin_libs do - start_type :permanent + start_type :load end application :emqx_authn do - start_type :permanent - overlay :application + start_type :load end application :emqx_authz do - start_type :permanent - overlay :application + start_type :load overlay do template "etc/acl.conf", "etc/acl.conf" @@ -71,44 +69,57 @@ defmodule EmqxReleaseHelper.Applications do end application :emqx_dashboard do - start_type :permanent - overlay :application + start_type :load end application :emqx_management do - start_type :permanent - overlay :application + start_type :load end application :emqx_statsd do - start_type :permanent - overlay :application + start_type :load end application :emqx_retainer do - start_type :permanent - overlay :application + start_type :load end application :emqx_rule_engine do - start_type :permanent - overlay :application + start_type :load end - application :emqx_rule_actions do - start_type :permanent - overlay :application + application :emqx_psk do + start_type :load end application :emqx_prometheus, %{release_type: :cloud} do - start_type :permanent - overlay :application + start_type :load end application :bcrypt, %{enable_bcrypt: true, release_type: :cloud} do start_type :permanent end + application :gproc do + start_type :load + end + + application :grpc do + start_type :load + end + + application :ekka do + start_type :load + end + + application :mnesia do + start_type :load + end + + application :ecpool do + start_type :load + end + application :xmerl, %{release_type: :cloud} do start_type :permanent end diff --git a/apps/emqx_release_helper/lib/emqx_release_helper/dsl/application.ex b/apps/emqx_release_helper/lib/emqx_release_helper/dsl/application.ex index b04882c26..77af841e7 100644 --- a/apps/emqx_release_helper/lib/emqx_release_helper/dsl/application.ex +++ b/apps/emqx_release_helper/lib/emqx_release_helper/dsl/application.ex @@ -44,19 +44,6 @@ defmodule EmqxReleaseHelper.DSL.Application do end end - defmacro overlay(:application) do - block = - Macro.escape( - quote do - &application_overlay/1 - end - ) - - quote do - @overlays [unquote(block) | @overlays] - end - end - defmacro overlay(do: block) do block = Macro.escape( @@ -131,25 +118,6 @@ defmodule EmqxReleaseHelper.DSL.Application do end end - def application_overlay( - %{app_source_path: app_source_path, release_path: release_path} = config - ) do - "#{app_source_path}/etc" - |> File.ls() - |> case do - {:ok, files} -> files - {:error, _} -> [] - end - |> Enum.filter(fn file -> String.ends_with?(file, ".conf") end) - |> Enum.each(fn file -> - EmqxReleaseHelper.DSL.Overlay.run_template( - "#{app_source_path}/etc/#{file}", - "#{release_path}/etc/plugins/#{file}", - config - ) - end) - end - defmacro __before_compile__(%Macro.Env{module: module}) do block = module diff --git a/mix.lock b/mix.lock index 68822fea7..0aa53b223 100644 --- a/mix.lock +++ b/mix.lock @@ -8,7 +8,7 @@ "ecpool": {:git, "https://github.com/emqx/ecpool.git", "0516d2cebd14654ef8c583c347e4a0b01363b86d", [tag: "0.5.1"]}, "eetcd": {:hex, :eetcd, "0.3.4", "27e8b4775230c53a9ef602f62a1603591302b40b2eb195d567edffb35b6cf1a2", [:rebar3], [{:gun, "1.3.3", [hex: :gun, repo: "hexpm", optional: false]}], "hexpm", "b763c0e1a9741d39a62f5a19186a342863eacbc769151c4e81db5790efecefca"}, "ekka": {:git, "https://github.com/emqx/ekka.git", "80e7439472164ce2b121cff523b979291cc7c9f3", [tag: "0.10.8"]}, - "emqtt": {:git, "https://github.com/emqx/emqtt.git", "9e867b1fcaadbfcce45ea75d3721f982907ae417", [tag: "v1.2.3"]}, + "emqtt": {:git, "https://github.com/emqx/emqtt.git", "25892ef48a979a9dfbd74d86133cb28cf11f3cf4", [tag: "1.4.3"]}, "emqx_http_lib": {:git, "https://github.com/emqx/emqx_http_lib.git", "9a1aafcbad1bb35392ebabc0cf102c7bce660432", [tag: "0.4.0"]}, "epgsql": {:git, "https://github.com/epgsql/epgsql.git", "895c8f9d53f08d09ec6a0301c56d3d6f270929f2", [tag: "4.4.0"]}, "esasl": {:git, "https://github.com/emqx/esasl.git", "1d4ab8d3ff7fd52018d3dddfec499933f9bb62b6", [tag: "0.1.0"]}, @@ -31,6 +31,7 @@ "pbkdf2": {:git, "https://github.com/emqx/erlang-pbkdf2.git", "45d9981209ea07a83a58cf85aaf8236457da4342", [tag: "2.0.4"]}, "poolboy": {:git, "https://github.com/emqx/poolboy.git", "29be47db8c2be38b18c908e43a80ebb7b9b6116b", [tag: "1.5.2"]}, "prometheus": {:git, "https://github.com/emqx/prometheus.erl.git", "a41488df09472448057d264ef520cf2f71d925f8", [tag: "v3.1.1"]}, + "quicer": {:git, "https://github.com/emqx/quic.git", "348c08a3f5a3b90861906fb436ff0ced453adfa2", [tag: "0.0.8"]}, "ranch": {:hex, :ranch, "2.1.0", "2261f9ed9574dcfcc444106b9f6da155e6e540b2f82ba3d42b339b93673b72a3", [:make, :rebar3], [], "hexpm", "244ee3fa2a6175270d8e1fc59024fd9dbc76294a321057de8f803b1479e76916"}, "recon": {:hex, :recon, "2.5.2", "cba53fa8db83ad968c9a652e09c3ed7ddcc4da434f27c3eaa9ca47ffb2b1ff03", [:mix, :rebar3], [], "hexpm", "2c7523c8dee91dff41f6b3d63cba2bd49eb6d2fe5bf1eec0df7f87eb5e230e1c"}, "replayq": {:git, "https://github.com/emqx/replayq", "9e5ba14d65ff1885ad85b6d33a859c01c322f273", [tag: "0.3.1"]}, diff --git a/rel/overlays/bin/emqx b/rel/overlays/bin/emqx index e6e27e7d9..7c269ae92 100755 --- a/rel/overlays/bin/emqx +++ b/rel/overlays/bin/emqx @@ -71,8 +71,8 @@ set_name () { SHORT_NAME="$(echo "$NAME" | awk -F'@' '{print $1}')" export ESCRIPT_NAME="$SHORT_NAME" - export NAME_TYPE - export NAME + export NAME_TYPE + export NAME } SED_REPLACE="sed -i " @@ -178,12 +178,12 @@ call_hocon() { nodetool () { command="$1"; shift "$RUNNER_ROOT_DIR/erts-$ERTS_VSN/bin/erl" \ - +B -noshell \ + +B -noshell \ -boot "$REL_VSN_DIR/$RELEASE_BOOT_SCRIPT_CLEAN" \ -boot_var RELEASE_LIB "$RELEASE_ROOT/lib" \ - -run escript start \ - -extra "$RUNNER_ROOT_DIR/bin/nodetool" \ - "$command" "$@" + -run escript start \ + -extra "$RUNNER_ROOT_DIR/bin/nodetool" \ + "$command" "$@" } set_name "$1"