Przeglądaj źródła

Merge pull request #12672 from zmstone/0308-load-cluster-hocon-to-generate-app.config

0308 load cluster hocon to generate app.config
Zaiming (Stone) Shi 1 rok temu
rodzic
commit
a00ce8fe41
2 zmienionych plików z 50 dodań i 15 usunięć
  1. 19 7
      bin/emqx
  2. 31 8
      dev

+ 19 - 7
bin/emqx

@@ -747,7 +747,11 @@ relx_start_command() {
 # Function to check configs without generating them
 # Function to check configs without generating them
 check_config() {
 check_config() {
     ## this command checks the configs without generating any files
     ## this command checks the configs without generating any files
-    call_hocon -v -s "$SCHEMA_MOD" -c "$EMQX_ETC_DIR"/emqx.conf check_schema
+    call_hocon -v \
+        -s "$SCHEMA_MOD" \
+        -c "$DATA_DIR"/configs/cluster.hocon \
+        -c "$EMQX_ETC_DIR"/emqx.conf \
+        check_schema
 }
 }
 
 
 # Function to generate app.config and vm.args
 # Function to generate app.config and vm.args
@@ -763,11 +767,19 @@ generate_config() {
     local NOW_TIME
     local NOW_TIME
     NOW_TIME="$(date +'%Y.%m.%d.%H.%M.%S')"
     NOW_TIME="$(date +'%Y.%m.%d.%H.%M.%S')"
 
 
-    ## this command populates two files: app.<time>.config and vm.<time>.args
-    ## NOTE: the generate command merges environment variables to the base config (emqx.conf),
-    ## but does not include the cluster-override.conf and local-override.conf
-    ## meaning, certain overrides will not be mapped to app.<time>.config file
-    call_hocon -v -t "$NOW_TIME" -s "$SCHEMA_MOD" -c "$EMQX_ETC_DIR"/emqx.conf -d "$DATA_DIR"/configs generate
+    ## This command populates two files: app.<time>.config and vm.<time>.args
+    ## It takes input sources and overlays values in below order:
+    ##   - $DATA_DIR/cluster.hocon (if exists)
+    ##   - etc/emqx.conf
+    ##   - environment variables starts with EMQX_ e.g. EMQX_NODE__ROLE
+    ##
+    ## NOTE: it's a known issue that cluster.hocon may change right after the node boots up
+    ##       because it has to sync cluster.hocon from other nodes.
+    call_hocon -v -t "$NOW_TIME" \
+        -s "$SCHEMA_MOD" \
+        -c "$DATA_DIR"/configs/cluster.hocon \
+        -c "$EMQX_ETC_DIR"/emqx.conf \
+        -d "$DATA_DIR"/configs generate
 
 
     ## filenames are per-hocon convention
     ## filenames are per-hocon convention
     CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
     CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
@@ -986,7 +998,7 @@ if [[ "$IS_BOOT_COMMAND" == 'yes' && "$(get_boot_config 'node.db_backend')" == "
     if ! (echo -e "$COMPATIBILITY_INFO" | $GREP -q 'MNESIA_OK'); then
     if ! (echo -e "$COMPATIBILITY_INFO" | $GREP -q 'MNESIA_OK'); then
       logwarn "DB Backend is RLOG, but an incompatible OTP version has been detected. Falling back to using Mnesia DB backend."
       logwarn "DB Backend is RLOG, but an incompatible OTP version has been detected. Falling back to using Mnesia DB backend."
       export EMQX_NODE__DB_BACKEND=mnesia
       export EMQX_NODE__DB_BACKEND=mnesia
-      export EMQX_NODE__DB_ROLE=core
+      export EMQX_NODE__ROLE=core
     fi
     fi
 fi
 fi
 
 

+ 31 - 8
dev

@@ -63,8 +63,23 @@ if [ -n "${DEBUG:-}" ]; then
 fi
 fi
 
 
 export HOCON_ENV_OVERRIDE_PREFIX='EMQX_'
 export HOCON_ENV_OVERRIDE_PREFIX='EMQX_'
-export EMQX_LOG__FILE__DEFAULT__ENABLE='false'
-export EMQX_LOG__CONSOLE__ENABLE='true'
+case "${EMQX_DEFAULT_LOG_HANDLER:-console}" in
+    console|default)
+        export EMQX_LOG__FILE__DEFAULT__ENABLE='false'
+        export EMQX_LOG__CONSOLE__ENABLE='true'
+        ;;
+    file)
+        export EMQX_LOG__FILE__DEFAULT__ENABLE='true'
+        export EMQX_LOG__CONSOLE__ENABLE='false'
+        ;;
+    both)
+        export EMQX_LOG__CONSOLE__ENABLE='true'
+        export EMQX_LOG__FILE__ENABLE='true'
+        ;;
+    *)
+        ;;
+esac
+
 SYSTEM="$(./scripts/get-distro.sh)"
 SYSTEM="$(./scripts/get-distro.sh)"
 if [ -n "${EMQX_NODE_NAME:-}" ]; then
 if [ -n "${EMQX_NODE_NAME:-}" ]; then
     export EMQX_NODE__NAME="${EMQX_NODE_NAME}"
     export EMQX_NODE__NAME="${EMQX_NODE_NAME}"
@@ -284,7 +299,8 @@ call_hocon() {
           os:putenv(\"EMQX_NODE__DB_BACKEND\", \"mnesia\"),
           os:putenv(\"EMQX_NODE__DB_BACKEND\", \"mnesia\"),
           os:putenv(\"EMQX_NODE__DB_ROLE\", \"core\")
           os:putenv(\"EMQX_NODE__DB_ROLE\", \"core\")
         end,
         end,
-        ok = hocon_cli:main([$args]),
+        {Time, ok} = timer:tc(fun() -> ok = hocon_cli:main([$args]) end),
+        io:format(user, \"Took ~pms to generate config~n\", [Time div 1000]),
         init:stop().
         init:stop().
     "
     "
     erl -noshell -eval "$erl_code"
     erl -noshell -eval "$erl_code"
@@ -297,11 +313,18 @@ generate_app_conf() {
     local NOW_TIME
     local NOW_TIME
     NOW_TIME="$(date +'%Y.%m.%d.%H.%M.%S')"
     NOW_TIME="$(date +'%Y.%m.%d.%H.%M.%S')"
 
 
-    ## this command populates two files: app.<time>.config and vm.<time>.args
-    ## NOTE: the generate command merges environment variables to the base config (emqx.conf),
-    ## but does not include the cluster-override.conf and local-override.conf
-    ## meaning, certain overrides will not be mapped to app.<time>.config file
-    call_hocon -v -t "$NOW_TIME" -s "$SCHEMA_MOD" -c "$EMQX_ETC_DIR"/emqx.conf -d "$EMQX_DATA_DIR"/configs generate
+    ## This command populates two files: app.<time>.config and vm.<time>.args
+    ## It takes input sources and overlays values in below order:
+    ##   - $DATA_DIR/cluster.hocon (if exists)
+    ##   - etc/emqx.conf
+    ##   - environment variables starts with EMQX_ e.g. EMQX_NODE__ROLE
+    ##
+    ## NOTE: it's a known issue that cluster.hocon may change right after the node boots up
+    ##       because it has to sync cluster.hocon from other nodes.
+    call_hocon -v -t "$NOW_TIME" -s "$SCHEMA_MOD" \
+        -c "$EMQX_DATA_DIR"/configs/cluster.hocon \
+        -c "$EMQX_ETC_DIR"/emqx.conf \
+        -d "$EMQX_DATA_DIR"/configs generate
 
 
     ## filenames are per-hocon convention
     ## filenames are per-hocon convention
     CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
     CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"