From f1262e04bfadd17888b6854312f97139915606ed Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Sun, 8 Aug 2021 11:23:01 +0200 Subject: [PATCH] feat: log error if timed out waiting after init:stop --- apps/emqx_machine/src/emqx_machine_terminator.erl | 3 ++- bin/emqx | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/emqx_machine/src/emqx_machine_terminator.erl b/apps/emqx_machine/src/emqx_machine_terminator.erl index a1f66deb6..74479a6d9 100644 --- a/apps/emqx_machine/src/emqx_machine_terminator.erl +++ b/apps/emqx_machine/src/emqx_machine_terminator.erl @@ -41,7 +41,8 @@ start_link() -> is_running() -> is_pid(whereis(?TERMINATOR)). -%% @doc Call terminator to stop applications, then issue init:stop() to terminat the VM. +%% @doc Call `emqx_machine_terminator' to stop applications +%% then call init:stop() stop beam. graceful() -> try _ = gen_server:call(?TERMINATOR, ?DO_IT, infinity) diff --git a/bin/emqx b/bin/emqx index c582f8fbf..6b6a6504c 100755 --- a/bin/emqx +++ b/bin/emqx @@ -480,14 +480,19 @@ case "$1" in # Wait for the node to completely stop... PID="$(relx_get_pid)" if ! relx_nodetool "stop"; then - echoerr "emqx_graceful_shutdown_failed PID=[$PID]" + echoerr "Graceful shutdown failed PID=[$PID]" exit 1 fi - WAIT_TIME=30 + WAIT_TIME="${WAIT_FOR_ERLANG_STOP:-60}" if ! wait_for "$WAIT_TIME" is_down "$PID"; then - echoerr "emqx_pid_dangling_after ${WAIT_TIME} seconds PID=[$PID]" + msg="dangling after ${WAIT_TIME} seconds" + # also log to syslog + logger -t "${REL_NAME}[${PID}]" "STOP: $msg" + # log to user console + echoerr "STOP: $msg" exit 1 fi + logger -t "${REL_NAME}[${PID}]" "STOP: OK" ;; restart|reboot) @@ -612,7 +617,7 @@ case "$1" in $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG # Log the startup - logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}" + logger -t "${REL_NAME}[$$]" "EXEC: $* -- ${1+$ARGS}" # Start the VM exec "$@" -- ${1+$ARGS} @@ -653,7 +658,7 @@ case "$1" in $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG # Log the startup - logger -t "${REL_NAME}[$$]" "$* -- ${1+$ARGS}" + logger -t "${REL_NAME}[$$]" "EXEC: $* -- ${1+$ARGS}" # Start the VM exec "$@" -- ${1+$ARGS}