4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
12 # * http://www.apache.org/licenses/LICENSE-2.0
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
21 # Move regions off a server then stop it. Optionally restart and reload.
22 # Turn off the balancer before running this script.
24 echo "Usage: graceful_stop.sh [--config <conf-dir>] [-e] [--restart [--reload]] [--thrift] \
25 [--rest] [-n |--noack] [--maxthreads <number of threads>] [--movetimeout <timeout in seconds>] \
26 [-nob |--nobalancer] [-d |--designatedfile <file path>] [-x |--excludefile <file path>] <hostname>"
27 echo " thrift If we should stop/start thrift before/after the hbase stop/start"
28 echo " rest If we should stop/start rest before/after the hbase stop/start"
29 echo " restart If we should restart after graceful stop"
30 echo " reload Move offloaded regions back on to the restarted server"
31 echo " n|noack Enable noAck mode in RegionMover. This is a best effort mode for \
33 echo " maxthreads xx Limit the number of threads used by the region mover. Default value is 1."
34 echo " movetimeout xx Timeout for moving regions. If regions are not moved by the timeout value,\
35 exit with error. Default value is INT_MAX."
36 echo " hostname Hostname of server we are to stop"
37 echo " e|failfast Set -e so exit immediately if any command exits with non-zero status"
38 echo " nob|nobalancer Do not manage balancer states. This is only used as optimization in \
39 rolling_restart.sh to avoid multiple calls to hbase shell"
40 echo " d|designatedfile xx Designated file with <hostname:port> per line as unload targets"
41 echo " x|excludefile xx Exclude file should have <hostname:port> per line. We do not unload \
42 regions to hostnames given in exclude file"
51 bin
=`cd "$bin">/dev/null; pwd`
52 # This will set HBASE_HOME, etc.
53 .
"$bin"/hbase-config.sh
60 movetimeout
=2147483647
69 --thrift) thrift
=true
; shift;;
70 --rest) rest
=true
; shift;;
71 --restart) restart
=true
; shift;;
72 --reload) reload
=true
; shift;;
73 --failfast |
-e) failfast
=true
; shift;;
74 --noack |
-n) noack
="--noack"; shift;;
75 --maxthreads) shift; maxthreads
=$1; shift;;
76 --movetimeout) shift; movetimeout
=$1; shift;;
77 --nobalancer |
-nob) nob
=true
; shift;;
78 --designatedfile |
-d) shift; designatedfile
=$1; shift;;
79 --excludefile |
-x) shift; excludefile
=$1; shift;;
82 *) break;; # terminate while loop
86 # "$@" contains the rest. Must be at least the hostname left.
91 # Emit a log line w/ iso8901 date prefixed
93 echo `date +%Y-%m-%dT%H:%M:%S` $1
96 # See if we should set fail fast before we do anything.
97 if [ "$failfast" != "" ]; then
98 log
"Set failfast, will exit immediately if any command exits with non-zero status"
103 filename
="/tmp/$hostname"
106 localhostname
=`/bin/hostname`
108 if [ "$localhostname" == "$hostname" ]; then
112 if [ "$nob" == "true" ]; then
113 log
"[ $0 ] skipping disabling balancer -nob argument is used"
114 HBASE_BALANCER_STATE
=false
116 log
"Disabling load balancer"
117 HBASE_BALANCER_STATE
=$
(echo 'balance_switch false' |
"$bin"/hbase
--config "${HBASE_CONF_DIR}" shell
-n |
tail -1)
118 log
"Previous balancer state was $HBASE_BALANCER_STATE"
121 unload_args
="--filename $filename --maxthreads $maxthreads $noack --operation unload \
122 --timeout $movetimeout --regionserverhost $hostname"
124 if [ "$designatedfile" != "" ]; then
125 unload_args
="$unload_args --designatedfile $designatedfile"
128 if [ "$excludefile" != "" ]; then
129 unload_args
="$unload_args --excludefile $excludefile"
132 log
"Unloading $hostname region(s)"
133 HBASE_NOEXEC
=true
"$bin"/hbase
--config ${HBASE_CONF_DIR} org.apache.hadoop.hbase.util.RegionMover \
135 log
"Unloaded $hostname region(s)"
137 # Stop the server(s). Have to put hostname into its own little file for hbase-daemons.sh
138 hosts
="/tmp/$(basename $0).$$.tmp"
139 echo $hostname >> $hosts
140 if [ "$thrift" != "" ]; then
141 log
"Stopping thrift server on $hostname"
142 if [ "$local" == true
]; then
143 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} stop thrift
145 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} stop thrift
148 if [ "$rest" != "" ]; then
149 log
"Stopping rest server on $hostname"
150 if [ "$local" == true
]; then
151 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} stop rest
153 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} stop rest
156 log
"Stopping regionserver on $hostname"
157 if [ "$local" == true
]; then
158 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} stop regionserver
160 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} stop regionserver
162 if [ "$restart" != "" ]; then
163 log
"Restarting regionserver on $hostname"
164 if [ "$local" == true
]; then
165 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} start regionserver
167 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} start regionserver
169 if [ "$thrift" != "" ]; then
170 log
"Restarting thrift server on $hostname"
171 # -b 0.0.0.0 says listen on all interfaces rather than just default.
172 if [ "$local" == true
]; then
173 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} start thrift
-b 0.0.0.0
175 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} start thrift
-b 0.0.0.0
178 if [ "$rest" != "" ]; then
179 log
"Restarting rest server on $hostname"
180 if [ "$local" == true
]; then
181 "$bin"/hbase-daemon.sh
--config ${HBASE_CONF_DIR} start rest
183 "$bin"/hbase-daemons.sh
--config ${HBASE_CONF_DIR} --hosts ${hosts} start rest
186 if [ "$reload" != "" ]; then
187 log
"Reloading $hostname region(s)"
188 HBASE_NOEXEC
=true
"$bin"/hbase
--config ${HBASE_CONF_DIR} \
189 org.apache.hadoop.hbase.util.RegionMover
--filename $filename --maxthreads $maxthreads $noack \
190 --operation "load" --timeout $movetimeout --regionserverhost $hostname
191 log
"Reloaded $hostname region(s)"
195 # Restore balancer state
196 if [ "$HBASE_BALANCER_STATE" != "false" ] && [ "$nob" != "true" ]; then
197 log
"Restoring balancer state to $HBASE_BALANCER_STATE"
198 echo "balance_switch $HBASE_BALANCER_STATE" |
"$bin"/hbase
--config ${HBASE_CONF_DIR} shell
&> /dev
/null
200 log
"[ $0 ] skipping restoring balancer"
204 trap "rm -f "/tmp
/$
(basename $0).
*.tmp
" &> /dev/null" EXIT