Skip to content

Commit 3e59f4d

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.
1 parent 2bbe036 commit 3e59f4d

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

bin/hbase-daemon.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,33 @@ 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+
waitForProcessEnd "$(cat "${HBASE_PID}")" "${command}"
93+
fi
94+
cleanAfterRun
95+
}
96+
97+
cleanAfterRun() {
98+
rm -f "${HBASE_PID}" > /dev/null 2>&1
99+
if [ -f "${HBASE_ZNODE_FILE}" ]; then
100+
if [ "${command}" = "master" ]; then
101+
HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS" "${bin}/hbase" master clear > /dev/null 2>&1
91102
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
103+
# call ZK to delete the node
104+
ZNODE="$(cat "${HBASE_ZNODE_FILE}")"
105+
HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS" "${bin}/hbase" zkcli delete "${ZNODE}" > /dev/null 2>&1
95106
fi
96-
rm ${HBASE_ZNODE_FILE}
107+
rm -f "${HBASE_ZNODE_FILE}" > /dev/null 2>&1
97108
fi
98109
}
99110

@@ -225,7 +236,9 @@ case $startStop in
225236
;;
226237

227238
(foreground_start)
228-
trap cleanAfterRun SIGHUP SIGINT SIGTERM EXIT
239+
trap sighup_handler HUP
240+
trap sigterm_handler INT TERM EXIT
241+
229242
if [ "$HBASE_NO_REDIRECT_LOG" != "" ]; then
230243
# NO REDIRECT
231244
echo "`date` Starting $command on `hostname`"

0 commit comments

Comments
 (0)