Skip to content

Commit

Permalink
fix: load cluster.hocon when generate app.<time>.config
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Mar 8, 2024
1 parent 62f896b commit 73af8af
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
24 changes: 18 additions & 6 deletions bin/emqx
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,11 @@ relx_start_command() {
# Function to check configs without generating them
check_config() {
## 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
Expand All @@ -763,11 +767,19 @@ generate_config() {
local NOW_TIME
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
CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
Expand Down
39 changes: 31 additions & 8 deletions dev
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,23 @@ if [ -n "${DEBUG:-}" ]; then
fi

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)"
if [ -n "${EMQX_NODE_NAME:-}" ]; then
export EMQX_NODE__NAME="${EMQX_NODE_NAME}"
Expand Down Expand Up @@ -284,7 +299,8 @@ call_hocon() {
os:putenv(\"EMQX_NODE__DB_BACKEND\", \"mnesia\"),
os:putenv(\"EMQX_NODE__DB_ROLE\", \"core\")
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().
"
erl -noshell -eval "$erl_code"
Expand All @@ -297,11 +313,18 @@ generate_app_conf() {
local NOW_TIME
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
CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config"
Expand Down

0 comments on commit 73af8af

Please sign in to comment.