diff --git a/bin/hbase-common.sh b/bin/hbase-common.sh new file mode 100644 index 00000000000..c9d4ef3efa4 --- /dev/null +++ b/bin/hbase-common.sh @@ -0,0 +1,40 @@ +## +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## + +#Shared function to wait for a process end. Take the pid and the command name as parameters +waitForProcessEnd() { + pidKilled=$1 + commandName=$2 + processedAt=`date +%s` + while kill -0 $pidKilled > /dev/null 2>&1; + do + echo -n "." + sleep 1; + # if process persists more than $HBASE_STOP_TIMEOUT (default 1200 sec) no mercy + if [ $(( `date +%s` - $processedAt )) -gt ${HBASE_STOP_TIMEOUT:-1200} ]; then + break; + fi + done + # process still there : kill -9 + if kill -0 $pidKilled > /dev/null 2>&1; then + echo -n force stopping $commandName with kill -9 $pidKilled + kill -9 $pidKilled > /dev/null 2>&1 + fi + # Add a CR after we're done w/ dots. + echo +} diff --git a/bin/hbase-daemon.sh b/bin/hbase-daemon.sh index 7fb5458eda9..70ead10fd8c 100755 --- a/bin/hbase-daemon.sh +++ b/bin/hbase-daemon.sh @@ -29,6 +29,8 @@ # HBASE_PID_DIR The pid files are stored. /tmp by default. # HBASE_IDENT_STRING A string representing this instance of hadoop. $USER by default # HBASE_NICENESS The scheduling priority for daemons. Defaults to 0. +# HBASE_STOP_TIMEOUT Time, in seconds, after which we kill -9 the server if it has not stopped. +# Default 1200 seconds. # # Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh @@ -46,6 +48,7 @@ bin=`dirname "${BASH_SOURCE-$0}"` bin=`cd "$bin">/dev/null; pwd` . "$bin"/hbase-config.sh +. "$bin"/hbase-common.sh # get arguments startStop=$1 @@ -235,28 +238,13 @@ case $startStop in rm -f "$HBASE_START_FILE" if [ -f $pid ]; then pidToKill=`cat $pid` - processedAt=`date +%s` # kill -0 == see if the PID exists if kill -0 $pidToKill > /dev/null 2>&1; then echo -n stopping $command echo "`date` Terminating $command" >> $loglog kill $pidToKill > /dev/null 2>&1 - while kill -0 $pidToKill > /dev/null 2>&1; - do - echo -n "." - sleep 1; - # if process persists more than $HBASE_STOP_TIMEOUT (default 1200 sec) no mercy - if [ $(( `date +%s` - $processedAt )) -gt ${HBASE_STOP_TIMEOUT:-1200} ]; then - break; - fi - done - # process still there : kill kill - if kill -0 $pidToKill > /dev/null 2>&1; then - echo -n force stopping $command - kill -9 $pidToKill > /dev/null 2>&1 - fi + waitForProcessEnd $pidToKill $command rm $pid - echo else retval=$? echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval diff --git a/bin/stop-hbase.sh b/bin/stop-hbase.sh index 591ccdba694..34f38a8b3e0 100755 --- a/bin/stop-hbase.sh +++ b/bin/stop-hbase.sh @@ -28,6 +28,7 @@ bin=`dirname "${BASH_SOURCE-$0}"` bin=`cd "$bin">/dev/null; pwd` . "$bin"/hbase-config.sh +. "$bin"/hbase-common.sh # variables needed for stop command if [ "$HBASE_LOG_DIR" = "" ]; then @@ -52,13 +53,10 @@ nohup nice -n ${HBASE_NICENESS:-0} "$HBASE_HOME"/bin/hbase \ --config "${HBASE_CONF_DIR}" \ master stop "$@" > "$logout" 2>&1 < /dev/null & -while kill -0 `cat $pid` > /dev/null 2>&1; do - echo -n "." - sleep 1; -done +waitForProcessEnd `cat $pid` 'stop-master-command' + rm -f $pid -# Add a CR after we're done w/ dots. -echo + # distributed == false means that the HMaster will kill ZK when it exits # HBASE-6504 - only take the first line of the output in case verbose gc is on