From 9bfb24314fb74389a730effa4d81341d2123df5a Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Fri, 17 Feb 2023 11:43:07 +0100 Subject: [PATCH 1/2] HBASE-27651 hbase-daemon.sh foreground_start should propagate SIGHUP and SIGTERM Introduce separate `trap`s for SIGHUP vs. the rest. Treat `SIGINT`, `SIGKILL`, and `EXIT` identically, as before. Use the signal name without `SIG` prefix for increased portability, as per the POSIX man page for `trap`. `SIGTERM` handler will now honor `HBASE_STOP_TIMEOUT` as described in the file header. --- bin/hbase-daemon.sh | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/bin/hbase-daemon.sh b/bin/hbase-daemon.sh index 598e49c7413a..f280ec30a917 100755 --- a/bin/hbase-daemon.sh +++ b/bin/hbase-daemon.sh @@ -78,22 +78,33 @@ hbase_rotate_log () fi } -cleanAfterRun() { - if [ -f ${HBASE_PID} ]; then - # If the process is still running time to tear it down. - kill -9 `cat ${HBASE_PID}` > /dev/null 2>&1 - rm -f ${HBASE_PID} > /dev/null 2>&1 +function sighup_handler +{ + # pass through SIGHUP if we can + if [ -f "${HBASE_PID}" ] ; then + kill -s HUP "$(cat "${HBASE_PID}")" fi +} - if [ -f ${HBASE_ZNODE_FILE} ]; then - if [ "$command" = "master" ]; then - HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" $bin/hbase master clear > /dev/null 2>&1 +function sigterm_handler +{ + if [ -f "${HBASE_PID}" ]; then + waitForProcessEnd "$(cat "${HBASE_PID}")" "${command}" + fi + cleanAfterRun +} + +cleanAfterRun() { + rm -f "${HBASE_PID}" > /dev/null 2>&1 + if [ -f "${HBASE_ZNODE_FILE}" ]; then + if [ "${command}" = "master" ]; then + HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" "${bin}/hbase" master clear > /dev/null 2>&1 else - #call ZK to delete the node - ZNODE=`cat ${HBASE_ZNODE_FILE}` - HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" $bin/hbase zkcli delete ${ZNODE} > /dev/null 2>&1 + # call ZK to delete the node + ZNODE="$(cat "${HBASE_ZNODE_FILE}")" + HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" "${bin}/hbase" zkcli delete "${ZNODE}" > /dev/null 2>&1 fi - rm ${HBASE_ZNODE_FILE} + rm -f "${HBASE_ZNODE_FILE}" > /dev/null 2>&1 fi } @@ -225,7 +236,9 @@ case $startStop in ;; (foreground_start) - trap cleanAfterRun SIGHUP SIGINT SIGTERM EXIT + trap sighup_handler HUP + trap sigterm_handler INT TERM EXIT + if [ "$HBASE_NO_REDIRECT_LOG" != "" ]; then # NO REDIRECT echo "`date` Starting $command on `hostname`" From 4fdeeced03085bba87bde3293e3bfce9c027c36f Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Fri, 17 Mar 2023 16:06:52 +0100 Subject: [PATCH 2/2] term handler needs to send signal --- bin/hbase-daemon.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/hbase-daemon.sh b/bin/hbase-daemon.sh index f280ec30a917..b3514bfd42ae 100755 --- a/bin/hbase-daemon.sh +++ b/bin/hbase-daemon.sh @@ -89,6 +89,7 @@ function sighup_handler function sigterm_handler { if [ -f "${HBASE_PID}" ]; then + kill -s TERM "$(cat "${HBASE_PID}")" waitForProcessEnd "$(cat "${HBASE_PID}")" "${command}" fi cleanAfterRun