Merge pull request #9968 from zmstone/0213-check-node-already-started-before-cookie-warning
Refactor: Check node already started before cookie warning
This commit is contained in:
commit
83a7da8bc0
32
bin/emqx
32
bin/emqx
|
@ -453,9 +453,25 @@ if [ "$IS_ENTERPRISE" = 'yes' ]; then
|
||||||
CONF_KEYS+=( 'license.key' )
|
CONF_KEYS+=( 'license.key' )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
## Find the running node from 'ps -ef'
|
||||||
|
## The primary grep pattern is $RUNNER_ROOT_DIR because one can start multiple nodes at the same time
|
||||||
|
# shellcheck disable=SC2009
|
||||||
|
PS_LINE="$(ps -ef | $GREP '[e]mqx' | $GREP -v -E '(remsh|nodetool)' | $GREP -oE "\-[r]oot ${RUNNER_ROOT_DIR}.*" || true)"
|
||||||
|
if [ -n "${PS_LINE}" ]; then
|
||||||
|
RUNNING_NODES_COUNT="$(echo -e "$PS_LINE" | wc -l)"
|
||||||
|
else
|
||||||
|
RUNNING_NODES_COUNT=0
|
||||||
|
fi
|
||||||
|
|
||||||
# Turn off debug as the ps output can be quite noisy
|
# Turn off debug as the ps output can be quite noisy
|
||||||
set +x
|
set +x
|
||||||
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
|
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
|
||||||
|
if [ "$RUNNING_NODES_COUNT" -gt 0 ] && [ "$COMMAND" != 'check_config' ]; then
|
||||||
|
tmp_nodename=$(echo -e "$PS_LINE" | $GREP -oE "\s\-s?name.*" | awk '{print $2}' || true)
|
||||||
|
echo "Node ${tmp_nodename} is already running!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
[ -f "$EMQX_ETC_DIR"/emqx.conf ] || die "emqx.conf is not found in $EMQX_ETC_DIR" 1
|
[ -f "$EMQX_ETC_DIR"/emqx.conf ] || die "emqx.conf is not found in $EMQX_ETC_DIR" 1
|
||||||
maybe_use_portable_dynlibs
|
maybe_use_portable_dynlibs
|
||||||
if [ "${EMQX_BOOT_CONFIGS:-}" = '' ]; then
|
if [ "${EMQX_BOOT_CONFIGS:-}" = '' ]; then
|
||||||
|
@ -486,14 +502,9 @@ else
|
||||||
# then update the config in the file to 'node.name = "emqx@local.net"', after this change,
|
# then update the config in the file to 'node.name = "emqx@local.net"', after this change,
|
||||||
# there would be no way stop the running node 'emqx@127.0.0.1', because 'emqx stop' command
|
# there would be no way stop the running node 'emqx@127.0.0.1', because 'emqx stop' command
|
||||||
# would try to stop the new node instead.
|
# would try to stop the new node instead.
|
||||||
# * The primary grep pattern is $RUNNER_ROOT_DIR because one can start multiple nodes at the same time
|
|
||||||
# * The grep args like '[e]mqx' but not 'emqx' is to avoid greping the grep command itself
|
# * The grep args like '[e]mqx' but not 'emqx' is to avoid greping the grep command itself
|
||||||
# * The running 'remsh' and 'nodetool' processes must be excluded
|
# * The running 'remsh' and 'nodetool' processes must be excluded
|
||||||
# shellcheck disable=SC2009
|
if [ "$RUNNING_NODES_COUNT" -eq 1 ]; then
|
||||||
PS_LINE="$(ps -ef | $GREP '[e]mqx' | $GREP -v -E '(remsh|nodetool)' | $GREP -oE "\-[r]oot ${RUNNER_ROOT_DIR}.*" || true)"
|
|
||||||
[ "$DEBUG" -eq 1 ] && echo "EMQX processes: $PS_LINE"
|
|
||||||
running_nodes_count="$(echo -e "$PS_LINE" | wc -l)"
|
|
||||||
if [ "$running_nodes_count" -eq 1 ]; then
|
|
||||||
## only one emqx node is running, get running args from 'ps -ef' output
|
## only one emqx node is running, get running args from 'ps -ef' output
|
||||||
tmp_nodename=$(echo -e "$PS_LINE" | $GREP -oE "\s\-s?name.*" | awk '{print $2}' || true)
|
tmp_nodename=$(echo -e "$PS_LINE" | $GREP -oE "\s\-s?name.*" | awk '{print $2}' || true)
|
||||||
tmp_cookie=$(echo -e "$PS_LINE" | $GREP -oE "\s\-setcookie.*" | awk '{print $2}' || true)
|
tmp_cookie=$(echo -e "$PS_LINE" | $GREP -oE "\s\-setcookie.*" | awk '{print $2}' || true)
|
||||||
|
@ -913,11 +924,14 @@ if [ -z "$COOKIE" ]; then
|
||||||
COOKIE="$(get_boot_config 'node.cookie')"
|
COOKIE="$(get_boot_config 'node.cookie')"
|
||||||
fi
|
fi
|
||||||
[ -z "$COOKIE" ] && COOKIE="$EMQX_DEFAULT_ERLANG_COOKIE"
|
[ -z "$COOKIE" ] && COOKIE="$EMQX_DEFAULT_ERLANG_COOKIE"
|
||||||
|
|
||||||
|
maybe_warn_default_cookie() {
|
||||||
if [ $IS_BOOT_COMMAND = 'yes' ] && [ "$COOKIE" = "$EMQX_DEFAULT_ERLANG_COOKIE" ]; then
|
if [ $IS_BOOT_COMMAND = 'yes' ] && [ "$COOKIE" = "$EMQX_DEFAULT_ERLANG_COOKIE" ]; then
|
||||||
logwarn "Default (insecure) Erlang cookie is in use."
|
logwarn "Default (insecure) Erlang cookie is in use."
|
||||||
logwarn "Configure node.cookie in $EMQX_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE"
|
logwarn "Configure node.cookie in $EMQX_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE"
|
||||||
logwarn "NOTE: Use the same cookie for all nodes in the cluster."
|
logwarn "NOTE: Use the same cookie for all nodes in the cluster."
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
## check if OTP version has mnesia_hook feature; if not, fallback to
|
## check if OTP version has mnesia_hook feature; if not, fallback to
|
||||||
## using Mnesia DB backend.
|
## using Mnesia DB backend.
|
||||||
|
@ -933,10 +947,7 @@ cd "$RUNNER_ROOT_DIR"
|
||||||
|
|
||||||
case "${COMMAND}" in
|
case "${COMMAND}" in
|
||||||
start)
|
start)
|
||||||
# Make sure a node IS not running
|
maybe_warn_default_cookie
|
||||||
if relx_nodetool "ping" >/dev/null 2>&1; then
|
|
||||||
die "Node $NAME is already running!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# this flag passes down to console mode
|
# this flag passes down to console mode
|
||||||
# so we know it's intended to be run in daemon mode
|
# so we know it's intended to be run in daemon mode
|
||||||
|
@ -1108,6 +1119,7 @@ case "${COMMAND}" in
|
||||||
tr_log_to_env
|
tr_log_to_env
|
||||||
else
|
else
|
||||||
maybe_log_to_console
|
maybe_log_to_console
|
||||||
|
maybe_warn_default_cookie
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#generate app.config and vm.args
|
#generate app.config and vm.args
|
||||||
|
|
Loading…
Reference in New Issue