Merge pull request #7584 from zmstone/0411-allow-space-in-path
fix: make possible to have white spaces in root path
This commit is contained in:
commit
69b9be13cc
|
@ -10,6 +10,12 @@ File format:
|
||||||
- One list item per change topic
|
- One list item per change topic
|
||||||
Change log ends with a list of github PRs
|
Change log ends with a list of github PRs
|
||||||
|
|
||||||
|
## v4.3.15
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* Made possible for EMQX to boot from a Linux directory which has white spaces in its path.
|
||||||
|
|
||||||
## v4.3.14
|
## v4.3.14
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
399
bin/emqx
399
bin/emqx
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
|
RUNNER_ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
. "$ROOT_DIR"/releases/emqx_vars
|
. "$RUNNER_ROOT_DIR"/releases/emqx_vars
|
||||||
|
|
||||||
RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME"
|
RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME"
|
||||||
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
|
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
|
||||||
|
@ -31,6 +31,12 @@ ERTS_LIB_DIR="$ERTS_DIR/../lib"
|
||||||
# Echo to stderr on errors
|
# Echo to stderr on errors
|
||||||
echoerr() { echo "$*" 1>&2; }
|
echoerr() { echo "$*" 1>&2; }
|
||||||
|
|
||||||
|
assert_node_alive() {
|
||||||
|
if ! relx_nodetool "ping" > /dev/null; then
|
||||||
|
die "node_is_not_running!" 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_eralng_start() {
|
check_eralng_start() {
|
||||||
"$BINDIR/$PROGNAME" -noshell -boot "$REL_DIR/start_clean" -s crypto start -s init stop
|
"$BINDIR/$PROGNAME" -noshell -boot "$REL_DIR/start_clean" -s crypto start -s init stop
|
||||||
}
|
}
|
||||||
|
@ -60,62 +66,157 @@ fi
|
||||||
# cuttlefish try to read environment variables starting with "EMQX_"
|
# cuttlefish try to read environment variables starting with "EMQX_"
|
||||||
export CUTTLEFISH_ENV_OVERRIDE_PREFIX='EMQX_'
|
export CUTTLEFISH_ENV_OVERRIDE_PREFIX='EMQX_'
|
||||||
|
|
||||||
relx_usage() {
|
usage() {
|
||||||
command="$1"
|
local command="$1"
|
||||||
|
|
||||||
case "$command" in
|
case "$command" in
|
||||||
unpack)
|
start)
|
||||||
echo "Usage: $REL_NAME unpack [VERSION]"
|
echo "Start EMQX service in daemon mode"
|
||||||
echo "Unpacks a release package VERSION, it assumes that this"
|
;;
|
||||||
echo "release package tarball has already been deployed at one"
|
stop)
|
||||||
echo "of the following locations:"
|
echo "Stop the running EMQX program"
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
;;
|
||||||
echo " releases/<relname>-<version>.zip"
|
console)
|
||||||
;;
|
echo "Boot up EMQX service in an interactive Erlang shell"
|
||||||
install)
|
echo "This command needs a tty"
|
||||||
echo "Usage: $REL_NAME install [VERSION]"
|
;;
|
||||||
echo "Installs a release package VERSION, it assumes that this"
|
console_clean)
|
||||||
echo "release package tarball has already been deployed at one"
|
echo "This command does NOT boot up the EMQX service"
|
||||||
echo "of the following locations:"
|
echo "It only starts an interactive Erlang shell with all the"
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
echo "EMQX code available"
|
||||||
echo " releases/<relname>-<version>.zip"
|
;;
|
||||||
echo ""
|
foreground)
|
||||||
echo " --no-permanent Install release package VERSION but"
|
echo "Start EMQX in foreground mode without an interactive shell"
|
||||||
echo " don't make it permanent"
|
;;
|
||||||
;;
|
pid)
|
||||||
uninstall)
|
echo "Print out EMQX process identifier"
|
||||||
echo "Usage: $REL_NAME uninstall [VERSION]"
|
;;
|
||||||
echo "Uninstalls a release VERSION, it will only accept"
|
ping)
|
||||||
echo "versions that are not currently in use"
|
echo "Check if the EMQX node is up and running"
|
||||||
;;
|
echo "This command exit with 0 silently if node is running"
|
||||||
upgrade)
|
;;
|
||||||
echo "Usage: $REL_NAME upgrade [VERSION]"
|
escript)
|
||||||
echo "Upgrades the currently running release to VERSION, it assumes"
|
echo "Execute a escript using the Erlang runtime from EMQX package installation"
|
||||||
echo "that a release package tarball has already been deployed at one"
|
echo "For example $REL_NAME escript /path/to/my/escript my_arg1 my_arg2"
|
||||||
echo "of the following locations:"
|
;;
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
attach)
|
||||||
echo " releases/<relname>-<version>.zip"
|
echo "This command is applicable when EMQX is started in daemon mode."
|
||||||
echo ""
|
echo "It attaches the current shell to EMQX's control console"
|
||||||
echo " --no-permanent Install release package VERSION but"
|
echo "through a named pipe."
|
||||||
echo " don't make it permanent"
|
echo "WARNING: try to use the safer alternative, remote_console command."
|
||||||
;;
|
;;
|
||||||
downgrade)
|
remote_console)
|
||||||
echo "Usage: $REL_NAME downgrade [VERSION]"
|
echo "Start an interactive shell running an Erlang node which "
|
||||||
echo "Downgrades the currently running release to VERSION, it assumes"
|
echo "hidden-connects to the running EMQX node".
|
||||||
echo "that a release package tarball has already been deployed at one"
|
echo "This command is mostly used for troubleshooting."
|
||||||
echo "of the following locations:"
|
;;
|
||||||
echo " releases/<relname>-<version>.tar.gz"
|
ertspath)
|
||||||
echo " releases/<relname>-<version>.zip"
|
echo "Print path to Erlang runtime dir"
|
||||||
echo ""
|
;;
|
||||||
echo " --no-permanent Install release package VERSION but"
|
rpc)
|
||||||
echo " don't make it permanent"
|
echo "Usge $REL_NAME rpc MODULE FUNCTION [ARGS, ...]"
|
||||||
;;
|
echo "Connect to the EMQX node and make an Erlang RPC"
|
||||||
*)
|
echo "This command blocks for at most 60 seconds."
|
||||||
echo "Usage: $REL_NAME {start|start_boot <file>|ertspath|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|uninstall|versions|escript|rpc|rpcterms|eval|root_dir}"
|
echo "It exits with non-zero code in case of any RPC failure"
|
||||||
;;
|
echo "including connection error and runtime exception"
|
||||||
|
;;
|
||||||
|
rpcterms)
|
||||||
|
echo "Usge $REL_NAME rpcterms MODULE FUNCTION [ARGS, ...]"
|
||||||
|
echo "Connect to the EMQX node and make an Erlang RPC"
|
||||||
|
echo "The result of the RPC call is pretty-printed as an "
|
||||||
|
echo "Erlang term"
|
||||||
|
;;
|
||||||
|
root_dir)
|
||||||
|
echo "Print EMQX installation root dir"
|
||||||
|
;;
|
||||||
|
eval)
|
||||||
|
echo "Evaluate an Erlang expression in the EMQX node"
|
||||||
|
;;
|
||||||
|
versions)
|
||||||
|
echo "List installed EMQX versions and their status"
|
||||||
|
;;
|
||||||
|
unpack)
|
||||||
|
echo "Usage: $REL_NAME unpack [VERSION]"
|
||||||
|
echo "Unpacks a release package VERSION, it assumes that this"
|
||||||
|
echo "release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
echo "Usage: $REL_NAME install [VERSION]"
|
||||||
|
echo "Installs a release package VERSION, it assumes that this"
|
||||||
|
echo "release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
uninstall)
|
||||||
|
echo "Usage: $REL_NAME uninstall [VERSION]"
|
||||||
|
echo "Uninstalls a release VERSION, it will only accept"
|
||||||
|
echo "versions that are not currently in use"
|
||||||
|
;;
|
||||||
|
upgrade)
|
||||||
|
echo "Usage: $REL_NAME upgrade [VERSION]"
|
||||||
|
echo "Upgrades the currently running release to VERSION, it assumes"
|
||||||
|
echo "that a release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
downgrade)
|
||||||
|
echo "Usage: $REL_NAME downgrade [VERSION]"
|
||||||
|
echo "Downgrades the currently running release to VERSION, it assumes"
|
||||||
|
echo "that a release package tarball has already been deployed at one"
|
||||||
|
echo "of the following locations:"
|
||||||
|
echo " releases/<relname>-<version>.zip"
|
||||||
|
echo ""
|
||||||
|
echo " --no-permanent Install release package VERSION but"
|
||||||
|
echo " don't make it permanent"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $REL_NAME COMMAND [help]"
|
||||||
|
echo ''
|
||||||
|
echo "Commonly used COMMANDs:"
|
||||||
|
echo " start: Start EMQX in daemon mode"
|
||||||
|
echo " console: Start EMQX in an interactive Erlang shell"
|
||||||
|
echo " foreground: Start EMQX in foreground mode without an interactive shell"
|
||||||
|
echo " stop: Stop the running EMQX node"
|
||||||
|
echo " ctl: Administration commands, execute '$REL_NAME ctl help' for more details"
|
||||||
|
echo ''
|
||||||
|
echo "More:"
|
||||||
|
echo " Shell attach: remote_console | attach"
|
||||||
|
echo " Up/Down-grade: upgrade | downgrade | install | uninstall"
|
||||||
|
echo " Install info: ertspath | root_dir | versions"
|
||||||
|
echo " Runtime info: pid | ping | versions"
|
||||||
|
echo " Advanced: console_clean | escript | rpc | rpcterms | eval"
|
||||||
|
echo ''
|
||||||
|
echo "Execute '$REL_NAME COMMAND help' for more information"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COMMAND="${1:-}"
|
||||||
|
|
||||||
|
if [ -z "$COMMAND" ]; then
|
||||||
|
usage 'help'
|
||||||
|
exit 1
|
||||||
|
elif [ "$COMMAND" = 'help' ]; then
|
||||||
|
usage 'help'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${2:-}" = 'help' ]; then
|
||||||
|
## 'ctl' command has its own usage info
|
||||||
|
if [ "$COMMAND" != 'ctl' ]; then
|
||||||
|
usage "$COMMAND"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Simple way to check the correct user and fail early
|
# Simple way to check the correct user and fail early
|
||||||
check_user() {
|
check_user() {
|
||||||
# Validate that the user running the script is the owner of the
|
# Validate that the user running the script is the owner of the
|
||||||
|
@ -135,7 +236,6 @@ check_user() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Make sure the user running this script is the owner and/or su to that user
|
# Make sure the user running this script is the owner and/or su to that user
|
||||||
check_user "$@"
|
check_user "$@"
|
||||||
ES=$?
|
ES=$?
|
||||||
|
@ -146,7 +246,8 @@ fi
|
||||||
if [ -z "$WITH_EPMD" ]; then
|
if [ -z "$WITH_EPMD" ]; then
|
||||||
EPMD_ARG="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
|
EPMD_ARG="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
|
||||||
else
|
else
|
||||||
EPMD_ARG="-start_epmd true $PROTO_DIST_ARG"
|
PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | awk -F"= " '{print $NF}')
|
||||||
|
EPMD_ARG="-start_epmd true -proto_dist $PROTO_DIST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Warn the user if ulimit -n is less than 1024
|
# Warn the user if ulimit -n is less than 1024
|
||||||
|
@ -157,9 +258,6 @@ if [ "$ULIMIT_F" -lt 1024 ]; then
|
||||||
echo "!!!!"
|
echo "!!!!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# By default, use cuttlefish to generate app.config and vm.args
|
|
||||||
CUTTLEFISH="${USE_CUTTLEFISH:-yes}"
|
|
||||||
|
|
||||||
SED_REPLACE="sed -i "
|
SED_REPLACE="sed -i "
|
||||||
case $(sed --help 2>&1) in
|
case $(sed --help 2>&1) in
|
||||||
*GNU*) SED_REPLACE="sed -i ";;
|
*GNU*) SED_REPLACE="sed -i ";;
|
||||||
|
@ -230,73 +328,69 @@ relx_start_command() {
|
||||||
"$START_OPTION"
|
"$START_OPTION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
echo -e "${1}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
|
||||||
|
}
|
||||||
|
|
||||||
# Function to generate app.config and vm.args
|
# Function to generate app.config and vm.args
|
||||||
generate_config() {
|
generate_config() {
|
||||||
## Delete the *.siz files first or it cann't start after
|
## Delete the *.siz files first or it cann't start after
|
||||||
## changing the config 'log.rotation.size'
|
## changing the config 'log.rotation.size'
|
||||||
rm -rf "${RUNNER_LOG_DIR}"/*.siz
|
rm -rf "${RUNNER_LOG_DIR}"/*.siz
|
||||||
|
|
||||||
if [ "$CUTTLEFISH" != "yes" ]; then
|
EMQX_LICENSE_CONF_OPTION=""
|
||||||
# Note: we have added a parameter '-vm_args' to this. It
|
if [ "${EMQX_LICENSE_CONF:-}" != "" ]; then
|
||||||
# appears redundant but it is not! the erlang vm allows us to
|
EMQX_LICENSE_CONF_OPTION="-i ${EMQX_LICENSE_CONF}"
|
||||||
# access all arguments to the erl command EXCEPT '-args_file',
|
|
||||||
# so in order to get access to this file location from within
|
|
||||||
# the vm, we need to pass it in twice.
|
|
||||||
CONFIG_ARGS=" -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -vm_args $RUNNER_ETC_DIR/vm.args "
|
|
||||||
else
|
|
||||||
EMQX_LICENSE_CONF_OPTION=""
|
|
||||||
if [ "${EMQX_LICENSE_CONF:-}" != "" ]; then
|
|
||||||
EMQX_LICENSE_CONF_OPTION="-i ${EMQX_LICENSE_CONF}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
set +e
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
CUTTLEFISH_OUTPUT="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/cuttlefish -v -i "$REL_DIR"/emqx.schema $EMQX_LICENSE_CONF_OPTION -c "$RUNNER_ETC_DIR"/emqx.conf -d "$RUNNER_DATA_DIR"/configs generate)"
|
|
||||||
# shellcheck disable=SC2181
|
|
||||||
RESULT=$?
|
|
||||||
set -e
|
|
||||||
if [ $RESULT -gt 0 ]; then
|
|
||||||
echo "$CUTTLEFISH_OUTPUT"
|
|
||||||
exit $RESULT
|
|
||||||
fi
|
|
||||||
# print override from environment variables (EMQX_*)
|
|
||||||
echo "$CUTTLEFISH_OUTPUT" | sed -e '$d'
|
|
||||||
CONFIG_ARGS=$(echo "$CUTTLEFISH_OUTPUT" | tail -n 1)
|
|
||||||
|
|
||||||
## Merge cuttlefish generated *.args into the vm.args
|
|
||||||
CUTTLE_GEN_ARG_FILE=$(echo "$CONFIG_ARGS" | sed -n 's/^.*\(vm_args[[:space:]]\)//p' | awk '{print $1}')
|
|
||||||
TMP_ARG_FILE="$RUNNER_DATA_DIR/configs/vm.args.tmp"
|
|
||||||
cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
|
|
||||||
echo "" >> "$TMP_ARG_FILE"
|
|
||||||
echo "-pa ${REL_DIR}/consolidated" >> "$TMP_ARG_FILE"
|
|
||||||
sed '/^#/d' "$CUTTLE_GEN_ARG_FILE" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
|
|
||||||
ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
|
|
||||||
ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
|
|
||||||
if [ "$ARG_KEY" = '' ]; then
|
|
||||||
## for the flags, e.g. -heart -emu_args etc
|
|
||||||
ARG_KEY=$(echo "$ARG_LINE" | awk '{print $1}')
|
|
||||||
ARG_VALUE=''
|
|
||||||
TMP_ARG_KEY=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $1}')
|
|
||||||
if [ "$TMP_ARG_KEY" = '' ]; then
|
|
||||||
echo "$ARG_KEY" >> "$TMP_ARG_FILE"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $NF}')
|
|
||||||
if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
|
|
||||||
if [ -n "$TMP_ARG_VALUE" ]; then
|
|
||||||
sh -c "$SED_REPLACE 's/^$ARG_KEY.*$/$ARG_LINE/' $TMP_ARG_FILE"
|
|
||||||
else
|
|
||||||
echo "$ARG_LINE" >> "$TMP_ARG_FILE"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
set +e
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if ! relx_nodetool chkconfig $CONFIG_ARGS; then
|
CUTTLEFISH_OUTPUT="$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/cuttlefish -v -i "$REL_DIR"/emqx.schema $EMQX_LICENSE_CONF_OPTION -c "$RUNNER_ETC_DIR"/emqx.conf -d "$RUNNER_DATA_DIR"/configs generate)"
|
||||||
echoerr "Error reading $CONFIG_ARGS"
|
# shellcheck disable=SC2181
|
||||||
|
RESULT=$?
|
||||||
|
set -e
|
||||||
|
if [ $RESULT -gt 0 ]; then
|
||||||
|
echo "$CUTTLEFISH_OUTPUT"
|
||||||
|
exit $RESULT
|
||||||
|
fi
|
||||||
|
## transform a single line args list like '-config ... -args_file ... -vm_args ...' to lines and get path for each file respectively
|
||||||
|
## NOTE: the -args_file and -vm_args are the same file passed twice because args_file is used by beam, but not possible to get at runtime
|
||||||
|
## by calling init:get_arguments/0
|
||||||
|
lines="$(echo "$CUTTLEFISH_OUTPUT" | tail -1 | sed 's/-config/\nconfig=/g' | sed 's/-args_file/\nargs_file=/g' | sed 's/-vm_args/\nvm_args=/g')"
|
||||||
|
CONFIG_FILE="$(trim "$(echo -e "$lines" | grep 'config=' | sed 's/config=//g')")"
|
||||||
|
CUTTLE_GEN_ARG_FILE="$(trim "$(echo -e "$lines" | grep 'vm_args=' | sed 's/vm_args=//g')")"
|
||||||
|
|
||||||
|
## Merge cuttlefish generated *.args into the vm.args
|
||||||
|
TMP_ARG_FILE="$RUNNER_DATA_DIR/configs/vm.args.tmp"
|
||||||
|
cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
|
||||||
|
echo "" >> "$TMP_ARG_FILE"
|
||||||
|
echo "-pa \"${REL_DIR}/consolidated\"" >> "$TMP_ARG_FILE"
|
||||||
|
sed '/^#/d' "$CUTTLE_GEN_ARG_FILE" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
|
||||||
|
ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
|
||||||
|
ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
|
||||||
|
if [ "$ARG_KEY" = '' ]; then
|
||||||
|
## for the flags, e.g. -heart -emu_args etc
|
||||||
|
ARG_KEY=$(echo "$ARG_LINE" | awk '{print $1}')
|
||||||
|
ARG_VALUE=''
|
||||||
|
TMP_ARG_KEY=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $1}')
|
||||||
|
if [ "$TMP_ARG_KEY" = '' ]; then
|
||||||
|
echo "$ARG_KEY" >> "$TMP_ARG_FILE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $NF}')
|
||||||
|
if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
|
||||||
|
if [ -n "$TMP_ARG_VALUE" ]; then
|
||||||
|
sh -c "$SED_REPLACE 's/^$ARG_KEY.*$/$ARG_LINE/' \"$TMP_ARG_FILE\""
|
||||||
|
else
|
||||||
|
echo "$ARG_LINE" >> "$TMP_ARG_FILE"
|
||||||
|
fi
|
||||||
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -341,15 +435,6 @@ wait_for() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use $CWD/etc/sys.config if exists
|
|
||||||
if [ -z "$RELX_CONFIG_PATH" ]; then
|
|
||||||
if [ -f "$RUNNER_ETC_DIR/sys.config" ]; then
|
|
||||||
RELX_CONFIG_PATH="-config $RUNNER_ETC_DIR/sys.config"
|
|
||||||
else
|
|
||||||
RELX_CONFIG_PATH=""
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
IS_BOOT_COMMAND='no'
|
IS_BOOT_COMMAND='no'
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start|start_boot)
|
start|start_boot)
|
||||||
|
@ -372,9 +457,10 @@ if [ -z "$NAME_ARG" ]; then
|
||||||
if [ "$IS_BOOT_COMMAND" = 'no' ]; then
|
if [ "$IS_BOOT_COMMAND" = 'no' ]; then
|
||||||
# for non-boot commands, inspect vm.<time>.args for node name
|
# for non-boot commands, inspect vm.<time>.args for node name
|
||||||
# shellcheck disable=SC2012,SC2086
|
# shellcheck disable=SC2012,SC2086
|
||||||
LATEST_VM_ARGS="$(ls -t $RUNNER_DATA_DIR/configs/vm.*.args | head -1)"
|
LATEST_VM_ARGS="$(ls -t $RUNNER_DATA_DIR/configs/vm.*.args 2>/dev/null | head -1)"
|
||||||
if [ -z "$LATEST_VM_ARGS" ]; then
|
if [ -z "$LATEST_VM_ARGS" ]; then
|
||||||
echo "For command $1, there is no vm.*.args config file found in $RUNNER_DATA_DIR/configs/"
|
echoerr "For command $1, there is no vm.*.args config file found in $RUNNER_DATA_DIR/configs/"
|
||||||
|
echoerr "Please make sure the node is initialized (started for at least once)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
NODENAME="$(grep -E '^-name' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
NODENAME="$(grep -E '^-name' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
||||||
|
@ -423,14 +509,6 @@ if [ -z "$COOKIE" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460
|
|
||||||
PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | awk -F"= " '{print $NF}')
|
|
||||||
if [ -z "$PROTO_DIST" ]; then
|
|
||||||
PROTO_DIST_ARG=""
|
|
||||||
else
|
|
||||||
PROTO_DIST_ARG="-proto_dist $PROTO_DIST"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$ROOTDIR"
|
cd "$ROOTDIR"
|
||||||
|
|
||||||
# User can specify an sname without @hostname
|
# User can specify an sname without @hostname
|
||||||
|
@ -667,14 +745,17 @@ case "$1" in
|
||||||
# Store passed arguments since they will be erased by `set`
|
# Store passed arguments since they will be erased by `set`
|
||||||
ARGS="$*"
|
ARGS="$*"
|
||||||
|
|
||||||
# shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
|
# shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace
|
||||||
# Build an array of arguments to pass to exec later on
|
# Build an array of arguments to pass to exec later on
|
||||||
# Build it here because this command will be used for logging.
|
# Build it here because this command will be used for logging.
|
||||||
set -- "$BINDIR/erlexec" \
|
set -- "$BINDIR/erlexec" \
|
||||||
-boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \
|
-boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \
|
||||||
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
|
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
|
||||||
-mnesia dir "\"${MNESIA_DATA_DIR}\"" \
|
-mnesia dir "\"${MNESIA_DATA_DIR}\"" \
|
||||||
$RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
|
-config "$CONFIG_FILE" \
|
||||||
|
-args_file "$CUTTLE_GEN_ARG_FILE" \
|
||||||
|
-vm_args "$CUTTLE_GEN_ARG_FILE" \
|
||||||
|
$EPMD_ARG
|
||||||
|
|
||||||
# Log the startup
|
# Log the startup
|
||||||
logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}"
|
logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}"
|
||||||
|
@ -708,14 +789,17 @@ case "$1" in
|
||||||
# Store passed arguments since they will be erased by `set`
|
# Store passed arguments since they will be erased by `set`
|
||||||
ARGS="$*"
|
ARGS="$*"
|
||||||
|
|
||||||
# shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
|
# shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace
|
||||||
# Build an array of arguments to pass to exec later on
|
# Build an array of arguments to pass to exec later on
|
||||||
# Build it here because this command will be used for logging.
|
# Build it here because this command will be used for logging.
|
||||||
set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \
|
set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \
|
||||||
-boot "$REL_DIR/$BOOTFILE" -mode "$CODE_LOADING_MODE" \
|
-boot "$REL_DIR/$BOOTFILE" -mode "$CODE_LOADING_MODE" \
|
||||||
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
|
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
|
||||||
-mnesia dir "\"${MNESIA_DATA_DIR}\"" \
|
-mnesia dir "\"${MNESIA_DATA_DIR}\"" \
|
||||||
$RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
|
-config "$CONFIG_FILE" \
|
||||||
|
-args_file "$CUTTLE_GEN_ARG_FILE" \
|
||||||
|
-vm_args "$CUTTLE_GEN_ARG_FILE" \
|
||||||
|
$EPMD_ARG
|
||||||
|
|
||||||
# Log the startup
|
# Log the startup
|
||||||
logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}"
|
logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}"
|
||||||
|
@ -726,50 +810,35 @@ case "$1" in
|
||||||
ertspath)
|
ertspath)
|
||||||
echo "$ERTS_PATH"
|
echo "$ERTS_PATH"
|
||||||
;;
|
;;
|
||||||
rpc)
|
|
||||||
# Make sure a node IS running
|
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
ctl)
|
||||||
|
assert_node_alive
|
||||||
shift
|
shift
|
||||||
|
relx_nodetool rpc_infinity emqx_ctl run_command "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
rpc)
|
||||||
|
assert_node_alive
|
||||||
|
shift
|
||||||
relx_nodetool rpc "$@"
|
relx_nodetool rpc "$@"
|
||||||
;;
|
;;
|
||||||
rpcterms)
|
rpcterms)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
relx_nodetool rpcterms "$@"
|
relx_nodetool rpcterms "$@"
|
||||||
;;
|
;;
|
||||||
root_dir)
|
root_dir)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
relx_nodetool "eval" 'code:root_dir()'
|
relx_nodetool "eval" 'code:root_dir()'
|
||||||
;;
|
;;
|
||||||
eval)
|
eval)
|
||||||
# Make sure a node IS running
|
assert_node_alive
|
||||||
if ! relx_nodetool "ping" > /dev/null; then
|
|
||||||
echo "Node is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
relx_nodetool "eval" "$@"
|
relx_nodetool "eval" "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
relx_usage "$1"
|
usage "$COMMAND"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
82
bin/emqx_ctl
82
bin/emqx_ctl
|
@ -2,83 +2,5 @@
|
||||||
# -*- tab-width:4;indent-tabs-mode:nil -*-
|
# -*- tab-width:4;indent-tabs-mode:nil -*-
|
||||||
# ex: ts=4 sw=4 et
|
# ex: ts=4 sw=4 et
|
||||||
|
|
||||||
set -e
|
THIS_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")" || true; pwd -P)"
|
||||||
|
exec "$THIS_DIR/emqx" ctl "$@"
|
||||||
ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
. "$ROOT_DIR"/releases/emqx_vars
|
|
||||||
|
|
||||||
export RUNNER_ROOT_DIR
|
|
||||||
export REL_VSN
|
|
||||||
|
|
||||||
# shellcheck disable=SC2012,SC2086
|
|
||||||
LATEST_VM_ARGS="$(ls -t $RUNNER_DATA_DIR/configs/vm.*.args | head -1)"
|
|
||||||
if [ -z "$LATEST_VM_ARGS" ]; then
|
|
||||||
echo "No vm.*.args config file found in $RUNNER_DATA_DIR/configs/"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Echo to stderr on errors
|
|
||||||
echoerr() { echo "$@" 1>&2; }
|
|
||||||
|
|
||||||
if [ -z "$WITH_EPMD" ]; then
|
|
||||||
EPMD_ARG="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
|
|
||||||
else
|
|
||||||
EPMD_ARG="-start_epmd true"
|
|
||||||
fi
|
|
||||||
|
|
||||||
relx_get_nodename() {
|
|
||||||
id="longname$(relx_gen_id)-${NAME}"
|
|
||||||
"$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell "${NAME_TYPE}" "$id"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Control a node
|
|
||||||
relx_nodetool() {
|
|
||||||
command="$1"; shift
|
|
||||||
|
|
||||||
ERL_FLAGS="$ERL_FLAGS $EPMD_ARG $PROTO_DIST_ARG" \
|
|
||||||
ERL_LIBS="${LIB_EKKA_DIR}:${ERL_LIBS:-}" \
|
|
||||||
"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
|
|
||||||
-setcookie "$COOKIE" "$command" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "$NAME_ARG" ]; then
|
|
||||||
NODENAME="${EMQX_NODE_NAME:-}"
|
|
||||||
[ -z "$NODENAME" ] && [ -n "$EMQX_NAME" ] && [ -n "$EMQX_HOST" ] && NODENAME="${EMQX_NAME}@${EMQX_HOST}"
|
|
||||||
[ -z "$NODENAME" ] && NODENAME="$(grep -E '^-name' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
|
||||||
if [ -z "$NODENAME" ]; then
|
|
||||||
echoerr "vm.args needs to have a -name parameter."
|
|
||||||
echoerr " -sname is not supported."
|
|
||||||
echoerr "perhaps you do not have read permissions on $RUNNER_ETC_DIR/emqx.conf"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
NAME_ARG="-name ${NODENAME# *}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extract the name type and name from the NAME_ARG for REMSH
|
|
||||||
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
|
|
||||||
NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
|
|
||||||
|
|
||||||
COOKIE="${EMQX_NODE_COOKIE:-}"
|
|
||||||
[ -z "$COOKIE" ] && COOKIE="$(grep -E '^-setcookie' "$LATEST_VM_ARGS" | awk '{print $2}')"
|
|
||||||
if [ -z "$COOKIE" ]; then
|
|
||||||
echoerr "Please set node.cookie in $RUNNER_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE_COOKIE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460
|
|
||||||
PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR"/emqx.conf 2> /dev/null | tail -1 | awk -F"= " '{print $NF}')
|
|
||||||
if [ -z "$PROTO_DIST" ]; then
|
|
||||||
PROTO_DIST_ARG=""
|
|
||||||
else
|
|
||||||
PROTO_DIST_ARG="-proto_dist $PROTO_DIST"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export ROOTDIR="$RUNNER_ROOT_DIR"
|
|
||||||
export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN"
|
|
||||||
export BINDIR="$ERTS_DIR/bin"
|
|
||||||
cd "$ROOTDIR"
|
|
||||||
|
|
||||||
relx_nodetool rpc emqx_ctl run_command "$@"
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
REL_VSN="{{ release_version }}"
|
REL_VSN="{{ release_version }}"
|
||||||
ERTS_VSN="{{ erts_vsn }}"
|
ERTS_VSN="{{ erts_vsn }}"
|
||||||
ERL_OPTS="{{ erl_opts }}"
|
ERL_OPTS="{{ erl_opts }}"
|
||||||
RUNNER_ROOT_DIR="{{ runner_root_dir }}"
|
|
||||||
RUNNER_BIN_DIR="{{ runner_bin_dir }}"
|
RUNNER_BIN_DIR="{{ runner_bin_dir }}"
|
||||||
RUNNER_LOG_DIR="{{ runner_log_dir }}"
|
RUNNER_LOG_DIR="{{ runner_log_dir }}"
|
||||||
RUNNER_LIB_DIR="{{ runner_lib_dir }}"
|
RUNNER_LIB_DIR="{{ runner_lib_dir }}"
|
||||||
|
|
|
@ -223,7 +223,6 @@ overlay_vars_pkg(bin) ->
|
||||||
, {platform_lib_dir, "lib"}
|
, {platform_lib_dir, "lib"}
|
||||||
, {platform_log_dir, "log"}
|
, {platform_log_dir, "log"}
|
||||||
, {platform_plugins_dir, "etc/plugins"}
|
, {platform_plugins_dir, "etc/plugins"}
|
||||||
, {runner_root_dir, "$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)"}
|
|
||||||
, {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"}
|
, {runner_bin_dir, "$RUNNER_ROOT_DIR/bin"}
|
||||||
, {runner_etc_dir, "$RUNNER_ROOT_DIR/etc"}
|
, {runner_etc_dir, "$RUNNER_ROOT_DIR/etc"}
|
||||||
, {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
, {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
||||||
|
@ -238,7 +237,6 @@ overlay_vars_pkg(pkg) ->
|
||||||
, {platform_lib_dir, ""}
|
, {platform_lib_dir, ""}
|
||||||
, {platform_log_dir, "/var/log/emqx"}
|
, {platform_log_dir, "/var/log/emqx"}
|
||||||
, {platform_plugins_dir, "/var/lib/emqx/plugins"}
|
, {platform_plugins_dir, "/var/lib/emqx/plugins"}
|
||||||
, {runner_root_dir, "/usr/lib/emqx"}
|
|
||||||
, {runner_bin_dir, "/usr/bin"}
|
, {runner_bin_dir, "/usr/bin"}
|
||||||
, {runner_etc_dir, "/etc/emqx"}
|
, {runner_etc_dir, "/etc/emqx"}
|
||||||
, {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
, {runner_lib_dir, "$RUNNER_ROOT_DIR/lib"}
|
||||||
|
|
Loading…
Reference in New Issue