Skip to content

Commit 5b50d70

Browse files
committed
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. Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Michael Stack <[email protected]>
1 parent fde0f4b commit 5b50d70

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

bin/hbase-daemon.sh

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,34 @@ hbase_rotate_log ()
7878
fi
7979
}
8080

81-
cleanAfterRun() {
82-
if [ -f ${HBASE_PID} ]; then
83-
# If the process is still running time to tear it down.
84-
kill -9 `cat ${HBASE_PID}` > /dev/null 2>&1
85-
rm -f ${HBASE_PID} > /dev/null 2>&1
81+
function sighup_handler
82+
{
83+
# pass through SIGHUP if we can
84+
if [ -f "${HBASE_PID}" ] ; then
85+
kill -s HUP "$(cat "${HBASE_PID}")"
8686
fi
87+
}
8788

88-
if [ -f ${HBASE_ZNODE_FILE} ]; then
89-
if [ "$command" = "master" ]; then
90-
HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" $bin/hbase master clear > /dev/null 2>&1
89+
function sigterm_handler
90+
{
91+
if [ -f "${HBASE_PID}" ]; then
92+
kill -s TERM "$(cat "${HBASE_PID}")"
93+
waitForProcessEnd "$(cat "${HBASE_PID}")" "${command}"
94+
fi
95+
cleanAfterRun
96+
}
97+
98+
cleanAfterRun() {
99+
rm -f "${HBASE_PID}" > /dev/null 2>&1
100+
if [ -f "${HBASE_ZNODE_FILE}" ]; then
101+
if [ "${command}" = "master" ]; then
102+
HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" "${bin}/hbase" master clear > /dev/null 2>&1
91103
else
92-
#call ZK to delete the node
93-
ZNODE=`cat ${HBASE_ZNODE_FILE}`
94-
HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" $bin/hbase zkcli delete ${ZNODE} > /dev/null 2>&1
104+
# call ZK to delete the node
105+
ZNODE="$(cat "${HBASE_ZNODE_FILE}")"
106+
HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" "${bin}/hbase" zkcli delete "${ZNODE}" > /dev/null 2>&1
95107
fi
96-
rm ${HBASE_ZNODE_FILE}
108+
rm -f "${HBASE_ZNODE_FILE}" > /dev/null 2>&1
97109
fi
98110
}
99111

@@ -225,7 +237,9 @@ case $startStop in
225237
;;
226238

227239
(foreground_start)
228-
trap cleanAfterRun SIGHUP SIGINT SIGTERM EXIT
240+
trap sighup_handler HUP
241+
trap sigterm_handler INT TERM EXIT
242+
229243
if [ "$HBASE_NO_REDIRECT_LOG" != "" ]; then
230244
# NO REDIRECT
231245
echo "`date` Starting $command on `hostname`"

0 commit comments

Comments
 (0)