HBASE-12964 Add the ability for hbase-daemon.sh to start in the foreground

This commit is contained in:
Elliott Clark 2015-02-03 10:58:15 -08:00
parent 7861e518ef
commit 5c1b08c5ca
1 changed files with 46 additions and 35 deletions

View File

@ -35,7 +35,7 @@
# Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh # Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh
usage="Usage: hbase-daemon.sh [--config <conf-dir>]\ usage="Usage: hbase-daemon.sh [--config <conf-dir>]\
(start|stop|restart|autorestart) <hbase-command> \ (start|stop|restart|autorestart|foreground_start) <hbase-command> \
<args...>" <args...>"
# if no args specified, show usage # if no args specified, show usage
@ -74,25 +74,31 @@ hbase_rotate_log ()
fi fi
} }
cleanZNode() { cleanAfterRun() {
if [ -f $HBASE_ZNODE_FILE ]; then 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
fi
if [ -f ${HBASE_ZNODE_FILE} ]; then
if [ "$command" = "master" ]; then if [ "$command" = "master" ]; then
$bin/hbase master clear > /dev/null 2>&1 $bin/hbase master clear > /dev/null 2>&1
else else
#call ZK to delete the node #call ZK to delete the node
ZNODE=`cat $HBASE_ZNODE_FILE` ZNODE=`cat ${HBASE_ZNODE_FILE}`
$bin/hbase zkcli delete $ZNODE > /dev/null 2>&1 $bin/hbase zkcli delete ${ZNODE} > /dev/null 2>&1
fi fi
rm $HBASE_ZNODE_FILE rm ${HBASE_ZNODE_FILE}
fi fi
} }
check_before_start(){ check_before_start(){
#ckeck if the process is not running #ckeck if the process is not running
mkdir -p "$HBASE_PID_DIR" mkdir -p "$HBASE_PID_DIR"
if [ -f $pid ]; then if [ -f $HBASE_PID ]; then
if kill -0 `cat $pid` > /dev/null 2>&1; then if kill -0 `cat $HBASE_PID` > /dev/null 2>&1; then
echo $command running as process `cat $pid`. Stop it first. echo $command running as process `cat $HBASE_PID`. Stop it first.
exit 1 exit 1
fi fi
fi fi
@ -153,18 +159,18 @@ if [ -z "${HBASE_SECURITY_LOGGER}" ]; then
export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"} export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"}
fi fi
logout=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.out HBASE_LOGOUT=${HBASE_LOGOUT:-"$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.out"}
loggc=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.gc HBASE_LOGGC=${HBASE_LOGGC:-"$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.gc"}
loglog="${HBASE_LOG_DIR}/${HBASE_LOGFILE}" HBASE_LOGLOG=${HBASE_LOGLOG:-"${HBASE_LOG_DIR}/${HBASE_LOGFILE}"}
pid=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pid HBASE_PID=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pid
export HBASE_ZNODE_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.znode export HBASE_ZNODE_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.znode
export HBASE_START_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.autorestart export HBASE_START_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.autorestart
if [ -n "$SERVER_GC_OPTS" ]; then if [ -n "$SERVER_GC_OPTS" ]; then
export SERVER_GC_OPTS=${SERVER_GC_OPTS/"-Xloggc:<FILE-PATH>"/"-Xloggc:${loggc}"} export SERVER_GC_OPTS=${SERVER_GC_OPTS/"-Xloggc:<FILE-PATH>"/"-Xloggc:${HBASE_LOGGC}"}
fi fi
if [ -n "$CLIENT_GC_OPTS" ]; then if [ -n "$CLIENT_GC_OPTS" ]; then
export CLIENT_GC_OPTS=${CLIENT_GC_OPTS/"-Xloggc:<FILE-PATH>"/"-Xloggc:${loggc}"} export CLIENT_GC_OPTS=${CLIENT_GC_OPTS/"-Xloggc:<FILE-PATH>"/"-Xloggc:${HBASE_LOGGC}"}
fi fi
# Set default scheduling priority # Set default scheduling priority
@ -179,30 +185,35 @@ case $startStop in
(start) (start)
check_before_start check_before_start
hbase_rotate_log $logout hbase_rotate_log $HBASE_LOGOUT
hbase_rotate_log $loggc hbase_rotate_log $HBASE_LOGGC
echo starting $command, logging to $logout echo starting $command, logging to $HBASE_LOGOUT
nohup $thiscmd --config "${HBASE_CONF_DIR}" internal_start $command $args < /dev/null > ${logout} 2>&1 & nohup $thiscmd --config "${HBASE_CONF_DIR}" \
sleep 1; head "${logout}" foreground_start $command $args < /dev/null > ${HBASE_LOGOUT} 2>&1 &
sleep 1; head "${HBASE_LOGOUT}"
;; ;;
(autorestart) (autorestart)
check_before_start check_before_start
hbase_rotate_log $logout hbase_rotate_log $HBASE_LOGOUT
hbase_rotate_log $loggc hbase_rotate_log $HBASE_LOGGC
nohup $thiscmd --config "${HBASE_CONF_DIR}" internal_autorestart $command $args < /dev/null > ${logout} 2>&1 & nohup $thiscmd --config "${HBASE_CONF_DIR}" \
internal_autorestart $command $args < /dev/null > ${HBASE_LOGOUT} 2>&1 &
;; ;;
(internal_start) (foreground_start)
# Add to the command log file vital stats on our environment. # Add to the command log file vital stats on our environment.
echo "`date` Starting $command on `hostname`" >> $loglog echo "`date` Starting $command on `hostname`" >> ${HBASE_LOGLOG}
echo "`ulimit -a`" >> $loglog 2>&1 `ulimit -a` >> "$HBASE_LOGLOG" 2>&1
nice -n $HBASE_NICENESS "$HBASE_HOME"/bin/hbase \ nice -n $HBASE_NICENESS "$HBASE_HOME"/bin/hbase \
--config "${HBASE_CONF_DIR}" \ --config "${HBASE_CONF_DIR}" \
$command "$@" start >> "$logout" 2>&1 & $command "$@" start >> ${HBASE_LOGOUT} 2>&1 &
echo $! > $pid echo $! > ${HBASE_PID}
# in case the parent shell gets the kill make sure to trap signals.
# Only one will get called. Either the trap or the flow will go through.
trap cleanAfterRun SIGHUP SIGINT SIGTERM EXIT
wait wait
cleanZNode cleanAfterRun
;; ;;
(internal_autorestart) (internal_autorestart)
@ -211,7 +222,7 @@ case $startStop in
while true while true
do do
lastLaunchDate=`date +%s` lastLaunchDate=`date +%s`
$thiscmd --config "${HBASE_CONF_DIR}" internal_start $command $args $thiscmd --config "${HBASE_CONF_DIR}" foreground_start $command $args
#if the file does not exist it means that it was not stopped properly by the stop command #if the file does not exist it means that it was not stopped properly by the stop command
if [ ! -f "$HBASE_START_FILE" ]; then if [ ! -f "$HBASE_START_FILE" ]; then
@ -247,12 +258,12 @@ case $startStop in
(stop) (stop)
rm -f "$HBASE_START_FILE" rm -f "$HBASE_START_FILE"
if [ -f $pid ]; then if [ -f $HBASE_PID ]; then
pidToKill=`cat $pid` pidToKill=`cat $HBASE_PID`
# kill -0 == see if the PID exists # kill -0 == see if the PID exists
if kill -0 $pidToKill > /dev/null 2>&1; then if kill -0 $pidToKill > /dev/null 2>&1; then
echo -n stopping $command echo -n stopping $command
echo "`date` Terminating $command" >> $loglog echo "`date` Terminating $command" >> $HBASE_LOGLOG
kill $pidToKill > /dev/null 2>&1 kill $pidToKill > /dev/null 2>&1
waitForProcessEnd $pidToKill $command waitForProcessEnd $pidToKill $command
else else
@ -260,9 +271,9 @@ case $startStop in
echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval
fi fi
else else
echo no $command to stop because no pid file $pid echo no $command to stop because no pid file $HBASE_PID
fi fi
rm -f $pid rm -f $HBASE_PID
;; ;;
(restart) (restart)