From 87aeead65356eaeed99f4680558e4b3d41a9090f Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Thu, 14 Jul 2022 17:11:15 +0800 Subject: [PATCH] feat: add check_conf cli to check config format --- CHANGES-4.3.md | 1 + bin/emqx | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index f23e5aeaa..ecca0dc8b 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -21,6 +21,7 @@ File format: ### Enhancements - HTTP API(GET /rules/) support for pagination and fuzzy filtering. [#8450] +- Add check_conf cli to check config format. [#8486] ## v4.3.16 diff --git a/bin/emqx b/bin/emqx index d6ce86e10..b70ce2e2f 100755 --- a/bin/emqx +++ b/bin/emqx @@ -196,6 +196,7 @@ usage() { echo " Up/Down-grade: upgrade | downgrade | install | uninstall" echo " Install info: ertspath | root_dir | versions" echo " Runtime info: pid | ping | versions" + echo " Configure check: check_conf" echo " Advanced: console_clean | escript | rpc | rpcterms | eval" echo '' echo "Execute '$REL_NAME COMMAND help' for more information" @@ -338,9 +339,12 @@ trim() { # Function to generate app.config and vm.args generate_config() { - ## Delete the *.siz files first or it cann't start after - ## changing the config 'log.rotation.size' - rm -rf "${RUNNER_LOG_DIR}"/*.siz + check_only="$1" + if [ "$check_only" != "check_only" ]; then + ## Delete the *.siz files first or it cann't start after + ## changing the config 'log.rotation.size' + rm -rf "${RUNNER_LOG_DIR}"/*.siz + fi set +e if [ "${EMQX_LICENSE_CONF:-}" = "" ]; then @@ -392,15 +396,22 @@ generate_config() { fi fi done - mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE" if ! relx_nodetool chkconfig -config "$CONFIG_FILE"; then echoerr "Error reading $CONFIG_FILE" exit 1 fi + + if [ "$check_only" = "check_only" ]; then + rm -rf "$TMP_ARG_FILE" + rm -rf "$CUTTLE_GEN_ARG_FILE" + rm -rf "$CONFIG_FILE" + else + mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE" + fi } -# Call bootstrapd for daemon commands like start/stop/console +# Call bootstrap for daemon commands like start/stop/console bootstrapd() { if [ -e "$RUNNER_DATA_DIR/.erlang.cookie" ]; then chown "$RUNNER_USER" "$RUNNER_DATA_DIR"/.erlang.cookie @@ -451,6 +462,9 @@ case "$1" in foreground) IS_BOOT_COMMAND='yes' ;; + check_conf) + IS_BOOT_COMMAND='yes' + ;; esac @@ -819,6 +833,10 @@ case "$1" in ertspath) echo "$ERTS_PATH" ;; + check_conf) + generate_config "check_only" + echo "$RUNNER_ETC_DIR/emqx.conf is ok" + ;; ctl) assert_node_alive