From c3bbe2c6b6a4a52841b1a1000b552333fa9f3725 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Tue, 15 Jun 2021 13:51:19 +0200 Subject: [PATCH] refactor(bin/emqx): invoke hocon_cli from nodetool nodetool has all lib paths set up correctly by reading the persisted RELEASES file calling hocon escript directly has two problems: 1. it may not be able to find the beams compiled 2. if we use ERL_LIBS, it may find the version after hot beam upgrade --- bin/emqx | 32 +++++++++++++++++++------------- bin/nodetool | 9 +++++++++ rebar.config.erl | 2 -- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/bin/emqx b/bin/emqx index ed66dee68..3e54dc17b 100755 --- a/bin/emqx +++ b/bin/emqx @@ -27,6 +27,15 @@ mkdir -p "$CONFIGS_DIR" # hocon try to read environment variables starting with "EMQX_" export HOCON_ENV_OVERRIDE_PREFIX='EMQX_' +export ROOTDIR="$RUNNER_ROOT_DIR" +export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN" +export BINDIR="$ERTS_DIR/bin" +export EMU="beam" +export PROGNAME="erl" +export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH" +export ERTS_LIB_DIR="$ERTS_DIR/../lib" +MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME" + relx_usage() { command="$1" @@ -183,6 +192,12 @@ relx_nodetool() { -setcookie "$COOKIE" "$command" "$@" } +call_hocon() { + export RUNNER_ROOT_DIR + export REL_VSN + "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" hocon "$@" +} + # Run an escript in the node's environment relx_escript() { shift; scriptpath="$1"; shift @@ -210,12 +225,12 @@ generate_config() { ## timestamp for each generation local NOW_TIME - NOW_TIME="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/hocon now_time)" + NOW_TIME="$(call_hocon now_time)" ## ths command populates two files: app.