diff --git a/bin/emqx b/bin/emqx index 472095e45..23b310cb1 100755 --- a/bin/emqx +++ b/bin/emqx @@ -9,9 +9,9 @@ if [ "$DEBUG" -eq 1 ]; then set -x fi -ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" +RUNNER_ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" # shellcheck disable=SC1090,SC1091 -. "$ROOT_DIR"/releases/emqx_vars +. "$RUNNER_ROOT_DIR"/releases/emqx_vars # defined in emqx_vars export RUNNER_ROOT_DIR @@ -31,12 +31,11 @@ mkdir -p "$RUNNER_LOG_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 ERTS_DIR="$RUNNER_ROOT_DIR/erts-$ERTS_VSN" export BINDIR="$ERTS_DIR/bin" export EMU="beam" export PROGNAME="erl" -export ERTS_LIB_DIR="$ERTS_DIR/../lib" +export ERTS_LIB_DIR="$RUNNER_ROOT_DIR/lib" DYNLIBS_DIR="$RUNNER_ROOT_DIR/dynlibs" # Echo to stderr on errors @@ -102,17 +101,18 @@ usage() { echo "For example $REL_NAME escript /path/to/my/escript my_arg1 my_arg2" ;; attach) - echo "This command is applicable when EMQX is started in daemon" - echo "mode. it attaches the current shell to EMQX's control console" - echo "through a named pipe" + echo "This command is applicable when EMQX is started in daemon mode." + echo "It attaches the current shell to EMQX's control console" + echo "through a named pipe." echo "WARNING: try to use the safer alternative, remote_console command." ;; remote_console) - echo "Start a dummy Erlang or Elixir node and hidden-connect EMQX to" - echo "with an interactive Erlang or Elixir shell" + echo "Start an interactive shell running an Erlang or Elixir node which " + echo "hidden-connects to the running EMQX node". + echo "This command is mostly used for troubleshooting." ;; ertspath) - echo "Print path to Erlang runtime dir" + echo "Print path to Erlang runtime bin dir" ;; rpc) echo "Usge $REL_NAME rpc MODULE FUNCTION [ARGS, ...]" @@ -131,7 +131,7 @@ usage() { echo "Print EMQX installation root dir" ;; eval) - echo "Evaluate an Erlang or Elxir expression in the EMQX node" + echo "Evaluate an Erlang or Elixir expression in the EMQX node" ;; eval-erl) echo "Evaluate an Erlang expression in the EMQX node, even on Elixir node" @@ -194,7 +194,7 @@ usage() { echo "More:" echo " Shell attach: remote_console | attach" echo " Up/Down-grade: upgrade | downgrade | install | uninstall" - echo " Install info: ertspath | root_dir | versions | root_dir" + echo " Install info: ertspath | root_dir | versions" echo " Runtime info: pid | ping | versions" echo " Advanced: console_clean | escript | rpc | rpcterms | eval | eval-erl" echo '' @@ -206,8 +206,11 @@ usage() { COMMAND="${1:-}" if [ -z "$COMMAND" ]; then - usage 'nil' + usage 'help' exit 1 +elif [ "$COMMAND" = 'help' ]; then + usage 'help' + exit 0 fi if [ "${2:-}" = 'help' ]; then @@ -269,9 +272,8 @@ if [ "$ES" -ne 0 ]; then exit $ES fi -# EPMD_ARG="-start_epmd true $PROTO_DIST_ARG" NO_EPMD="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka" -EPMD_ARG="${EPMD_ARG:-${NO_EPMD}}" +EPMD_ARGS="${EPMD_ARGS:-${NO_EPMD}}" # Warn the user if ulimit -n is less than 1024 ULIMIT_F=$(ulimit -n) @@ -302,33 +304,34 @@ relx_get_pid() { } # Connect to a remote node -relx_rem_sh() { +remsh() { # Generate a unique id used to allow multiple remsh to the same node # transparently id="remsh$(relx_gen_id)-${NAME}" # Get the node's ticktime so that we use the same thing. TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)" - # shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace + # shellcheck disable=SC2086 # Setup remote shell command to control node - if [ "$IS_ELIXIR" = "yes" ] - then - exec "$REL_DIR/iex" \ - --remsh "$NAME" \ - --boot-var RELEASE_LIB "$ERTS_LIB_DIR" \ - --cookie "$COOKIE" \ - --hidden \ - --erl "-kernel net_ticktime $TICKTIME" \ - --erl "$EPMD_ARG" \ - --erl "$NAME_TYPE $id" \ - --boot "$REL_DIR/start_clean" + if [ "$IS_ELIXIR" = no ] || [ "${EMQX_CONSOLE_FLAVOR:-}" = 'erl' ] ; then + set -- "$BINDIR/erl" "$NAME_TYPE" "$id" \ + -remsh "$NAME" -boot "$REL_DIR/start_clean" \ + -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ + -boot_var RELEASE_LIB "$ERTS_LIB_DIR" \ + -setcookie "$COOKIE" -hidden -kernel net_ticktime "$TICKTIME" \ + $EPMD_ARGS else - exec "$BINDIR/erl" "$NAME_TYPE" "$id" \ - -remsh "$NAME" -boot "$REL_DIR/start_clean" \ - -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ - -setcookie "$COOKIE" -hidden -kernel net_ticktime "$TICKTIME" \ - $EPMD_ARG + set -- "$REL_DIR/iex" \ + --remsh "$NAME" \ + --boot-var RELEASE_LIB "$ERTS_LIB_DIR" \ + --cookie "$COOKIE" \ + --hidden \ + --erl "-kernel net_ticktime $TICKTIME" \ + --erl "$EPMD_ARGS" \ + --erl "$NAME_TYPE $id" \ + --boot "$REL_DIR/start_clean" fi + exec "$@" } # Generate a random id @@ -337,13 +340,13 @@ relx_gen_id() { } call_nodetool() { - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$@" + "$ERTS_DIR/bin/escript" "$RUNNER_ROOT_DIR/bin/nodetool" "$@" } # Control a node relx_nodetool() { command="$1"; shift - ERL_FLAGS="${ERL_FLAGS:-} $EPMD_ARG" \ + ERL_FLAGS="${ERL_FLAGS:-} $EPMD_ARGS" \ call_nodetool "$NAME_TYPE" "$NAME" \ -setcookie "$COOKIE" "$command" "$@" } @@ -384,7 +387,7 @@ check_license() { # Run an escript in the node's environment relx_escript() { shift; scriptpath="$1"; shift - "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@" + "$ERTS_DIR/bin/escript" "$RUNNER_ROOT_DIR/$scriptpath" "$@" } # Output a start command for the last argument of run_erl @@ -403,6 +406,7 @@ CONFIGS_DIR="$DATA_DIR/configs" mkdir -p "$CONFIGS_DIR" # Function to generate app.config and vm.args +# sets two environment variables CONF_FILE and ARGS_FILE generate_config() { local name_type="$1" local node_name="$2" @@ -421,15 +425,8 @@ generate_config() { call_hocon -v -t "$NOW_TIME" -s "$SCHEMA_MOD" -c "$EMQX_ETC_DIR"/emqx.conf -d "$DATA_DIR"/configs generate ## filenames are per-hocon convention - local CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config" - local HOCON_GEN_ARG_FILE="$CONFIGS_DIR/vm.$NOW_TIME.args" - - # This is needed by the Elixir scripts. - # Do NOT append `.config`. - RELEASE_SYS_CONFIG="$CONFIGS_DIR/app.$NOW_TIME" - export RELEASE_SYS_CONFIG - - CONFIG_ARGS="-config $CONF_FILE -args_file $HOCON_GEN_ARG_FILE" + CONF_FILE="$CONFIGS_DIR/app.$NOW_TIME.config" + ARGS_FILE="$CONFIGS_DIR/vm.$NOW_TIME.args" ## Merge hocon generated *.args into the vm.args TMP_ARG_FILE="$CONFIGS_DIR/vm.args.tmp" @@ -439,7 +436,7 @@ generate_config() { ## read lines from generated vm.