From a681079ba769a22e1a0dbeef59c803af253a2400 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 3 Dec 2021 20:33:39 +0100 Subject: [PATCH] refactor: remove special env override from schema EMQX_NODE_NAME and EMQX_NODE_COOKIE are translated into EMQX_NODE__NAME and EMQX_NODE__COOKIE --- apps/emqx_conf/src/emqx_conf_schema.erl | 4 +--- bin/emqx | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index a84418916..571644aaf 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -257,14 +257,12 @@ fields("node") -> [ {"name", sc(string(), #{ default => "emqx@127.0.0.1" - , override_env => "EMQX_NODE_NAME" })} , {"cookie", sc(string(), #{ mapping => "vm_args.-setcookie", default => "emqxsecretcookie", - sensitive => true, - override_env => "EMQX_NODE_COOKIE" + sensitive => true })} , {"data_dir", sc(string(), diff --git a/bin/emqx b/bin/emqx index 920cd00f4..7862a98b8 100755 --- a/bin/emqx +++ b/bin/emqx @@ -454,18 +454,23 @@ case "${COMMAND}" in ;; esac +## make EMQX_NODE_COOKIE right +if [ -n "${EMQX_NODE_NAME:-}" ]; then + export EMQX_NODE__NAME="${EMQX_NODE_NAME}" + unset EMQX_NODE_NAME +fi ## Possible ways to configure emqx node name: ## 1. configure node.name in emqx.conf -## 2. override with environment variable EMQX_NODE_NAME +## 2. override with environment variable EMQX_NODE__NAME ## Node name is either short-name (without '@'), e.g. 'emqx' ## or long name (with '@') e.g. 'emqx@example.net' or 'emqx@127.0.0.1' -NAME="${EMQX_NODE_NAME:-}" +NAME="${EMQX_NODE__NAME:-}" if [ -z "$NAME" ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then # for boot commands, inspect emqx.conf for node name NAME="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")" else - vm_args_file="$(latest_vm_args 'EMQX_NODE_NAME')" + vm_args_file="$(latest_vm_args 'EMQX_NODE__NAME')" NAME="$(grep -E '^-s?name' "${vm_args_file}" | awk '{print $2}')" fi fi @@ -486,18 +491,23 @@ export ESCRIPT_NAME="$SHORT_NAME" PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}" -COOKIE="${EMQX_NODE_COOKIE:-}" +## make EMQX_NODE_COOKIE right +if [ -n "${EMQX_NODE_COOKIE:-}" ]; then + export EMQX_NODE__COOKIE="${EMQX_NODE_COOKIE}" + unset EMQX_NODE_COOKIE +fi +COOKIE="${EMQX_NODE__COOKIE:-}" if [ -z "$COOKIE" ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then COOKIE="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")" else - vm_args_file="$(latest_vm_args 'EMQX_NODE_COOKIE')" + vm_args_file="$(latest_vm_args 'EMQX_NODE__COOKIE')" COOKIE="$(grep -E '^-setcookie' "${vm_args_file}" | awk '{print $2}')" fi fi if [ -z "$COOKIE" ]; then - die "Please set node.cookie in $RUNNER_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE_COOKIE" + die "Please set node.cookie in $RUNNER_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE" fi cd "$ROOTDIR"