3 @rem
* Licensed to the Apache Software Foundation
(ASF
) under one
4 @rem
* or more contributor license agreements. See the NOTICE file
5 @rem
* distributed with this work
for additional information
6 @rem
* regarding copyright ownership. The ASF licenses this file
7 @rem
* to you under the Apache License
, Version
2.0 (the
8 @rem
* "License"); you may
not use this file except in compliance
9 @rem
* with the License. You may obtain a
copy of the License at
11 @rem
* http
://www.apache.org
/licenses
/LICENSE
-2.0
13 @rem
* Unless required by applicable law or agreed to in writing
, software
14 @rem
* distributed under the License is distributed on an
"AS IS" BASIS
,
15 @rem
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
, either express or implied.
16 @rem
* See the License
for the specific language governing permissions and
17 @rem
* limitations under the License.
20 @rem The hbase
command script. Based on the hadoop
command script putting
21 @rem in hbase classes
, libs and configurations ahead of hadoop
's.
23 @rem TODO: Narrow the amount of duplicated code.
25 @rem Environment Variables:
27 @rem JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
29 @rem HBASE_CLASSPATH Extra Java CLASSPATH entries.
31 @rem HBASE_HEAPSIZE The maximum amount of heap to use.
32 @rem Default is unset and uses the JVMs default setting
33 @rem (usually 1/4th of the available memory).
35 @rem HBASE_OPTS Extra Java runtime options.
37 @rem HBASE_CONF_DIR Alternate conf dir. Default is ${HBASE_HOME}/conf.
39 @rem HBASE_ROOT_LOGGER The root appender. Default is INFO,console
41 @rem JRUBY_HOME JRuby path: $JRUBY_HOME\lib\jruby.jar should exist.
42 @rem Defaults to the jar packaged with HBase.
44 @rem JRUBY_OPTS Extra options (eg '--1.9') passed to hbase.
45 @rem Empty by default.
46 @rem HBASE_SHELL_OPTS Extra options passed to the hbase shell.
47 @rem Empty by default.
50 setlocal enabledelayedexpansion
53 if not defined HBASE_BIN_PATH (
54 set HBASE_BIN_PATH=%%~dpi
58 if "%HBASE_BIN_PATH:~-1%" == "\" (
59 set HBASE_BIN_PATH=%HBASE_BIN_PATH:~0,-1%
71 rem This will set HBASE_HOME, etc.
72 set hbase-config-script=%HBASE_BIN_PATH%\hbase-config.cmd
73 call "%hbase-config-script%" %*
74 if "%1" == "--config" (
79 rem Detect if we are in hbase sources dir
82 if exist "%HBASE_HOME%\target" set in_dev_env=true
84 rem --service is an internal option. used by MSI setup to install HBase as a windows service
85 if "%1" == "--service" (
86 set service_entry=true
93 @rem if no args specified, show usage
94 if "%hbase-command%"=="" (
101 set JAVA_OFFHEAP_MAX=
103 rem check envvars which might override default args
104 if defined HBASE_HEAPSIZE (
105 set JAVA_HEAP_MAX=-Xmx%HBASE_HEAPSIZE%m
108 if defined HBASE_OFFHEAPSIZE (
109 set JAVA_OFFHEAP_MAX=-XX:MaxDirectMemory=%HBASE_OFFHEAPSIZE%m
112 set CLASSPATH=%HBASE_CONF_DIR%;%JAVA_HOME%\lib\tools.jar
114 rem Add maven target directory
115 set cached_classpath_filename=%HBASE_HOME%\hbase-build-configuration\target\cached_classpath.txt
116 if "%in_dev_env%"=="true" (
118 rem adding maven main classes to classpath
119 for /f %%i in ('dir /b
"%HBASE_HOME%\hbase-*"') do (
120 if exist %%i\target\classes set CLASSPATH=!CLASSPATH!;%%i\target\classes
123 rem adding maven test classes to classpath
124 rem For developers, add hbase classes to CLASSPATH
125 for /f %%i in ('dir /b
"%HBASE_HOME%\hbase-*"') do (
126 if exist %%i\target\test-classes set CLASSPATH=!CLASSPATH!;%%i\target\test-classes
129 if not exist "%cached_classpath_filename%" (
130 echo "As this is a development environment, we need %cached_classpath_filename% to be generated from maven (command: mvn install -DskipTests)"
134 for /f "delims=" %%i in ('type "%cached_classpath_filename%"') do set CLASSPATH=%CLASSPATH%;%%i
137 @rem For releases add hbase webapps to CLASSPATH
138 @rem Webapps must come first else it messes up Jetty
139 if exist "%HBASE_HOME%\hbase-webapps" (
140 set CLASSPATH=%CLASSPATH%;%HBASE_HOME%
143 if exist "%HBASE_HOME%\target\hbase-webapps" (
144 set CLASSPATH=%CLASSPATH%;%HBASE_HOME%\target
147 for /F %%f in ('dir /b
"%HBASE_HOME%\hbase*.jar" 2^
>nul
') do (
148 if not "%%f:~-11"=="sources.jar" (
149 set CLASSPATH=!CLASSPATH!;%HBASE_HOME%\%%f
153 @rem Add libs to CLASSPATH
154 if exist "%HBASE_HOME%\lib" (
155 set CLASSPATH=!CLASSPATH!;%HBASE_HOME%\lib\*
158 @rem Add user-specified CLASSPATH last
159 if defined HBASE_CLASSPATH (
160 set CLASSPATH=%CLASSPATH%;%HBASE_CLASSPATH%
163 @rem Default log directory and file
164 if not defined HBASE_LOG_DIR (
165 set HBASE_LOG_DIR=%HBASE_HOME%\logs
168 if not defined HBASE_LOGFILE (
169 set HBASE_LOGFILE=hbase.log
174 rem If avail, add Hadoop to the CLASSPATH and to the JAVA_LIBRARY_PATH
175 set PATH=%PATH%;"%HADOOP_HOME%\bin"
176 set HADOOP_IN_PATH=hadoop.cmd
178 if exist "%HADOOP_HOME%\bin\%HADOOP_IN_PATH%" (
179 set hadoopCpCommand=call %HADOOP_IN_PATH% classpath 2^>nul
180 for /f "eol= delims=" %%i in ('!hadoopCpCommand
!') do set CLASSPATH_FROM_HADOOP=%%i
181 if defined CLASSPATH_FROM_HADOOP (
182 set CLASSPATH=%CLASSPATH%;!CLASSPATH_FROM_HADOOP!
184 set HADOOP_CLASSPATH=%CLASSPATH%
186 set hadoopJLPCommand=call %HADOOP_IN_PATH% org.apache.hadoop.hbase.util.GetJavaProperty java.library.path 2^>nul
187 for /f "eol= delims=" %%i in ('!hadoopJLPCommand
!') do set HADOOP_JAVA_LIBRARY_PATH=%%i
188 if not defined JAVA_LIBRARY_PATH (
189 set JAVA_LIBRARY_PATH=!HADOOP_JAVA_LIBRARY_PATH!
191 set JAVA_LIBRARY_PATH=%JAVA_LIBRARY_PATH%;!HADOOP_JAVA_LIBRARY_PATH!
195 if exist "%HBASE_HOME%\build\native" (
196 set platformCommand=call %JAVA% -classpath "%CLASSPATH%" org.apache.hadoop.util.PlatformName
197 for /f %%i in ('!platformCommand
!') do set JAVA_PLATFORM=%%i
198 set _PATH_TO_APPEND=%HBASE_HOME%\build\native\!JAVA_PLATFORM!;%HBASE_HOME%\build\native\!JAVA_PLATFORM!\lib
199 if not defined JAVA_LIBRARY_PATH (
200 set JAVA_LIBRARY_PATH=!_PATH_TO_APPEND!
202 set JAVA_LIBRARY_PATH=%JAVA_LIBRARY_PATH%;!_PATH_TO_APPEND!
206 rem This loop would set %hbase-command-arguments%
209 if [%1]==[] goto :EndLoop
211 if not defined _hbasearguments (
212 set _hbasearguments=%1
214 set _hbasearguments=!_hbasearguments! %1
217 goto :MakeCmdArgsLoop
220 set hbase-command-arguments=%_hbasearguments%
222 @rem figure out which class to run
223 set corecommands=shell master regionserver thrift thrift2 rest avro hlog wal hbck hfile zookeeper zkcli mapredcp
224 for %%i in ( %corecommands% ) do (
225 if "%hbase-command%"=="%%i" set corecommand=true
228 if defined corecommand (
229 call :%hbase-command% %hbase-command-arguments%
231 if "%hbase-command%" == "classpath" (
235 if "%hbase-command%" == "version" (
236 set CLASS=org.apache.hadoop.hbase.util.VersionInfo
238 set CLASS=%hbase-command%
242 if not defined HBASE_IDENT_STRING (
243 set HBASE_IDENT_STRING=%USERNAME%
246 @rem Set the right GC options based on the what we are running
247 set servercommands=master regionserver thrift thrift2 rest avro zookeeper
248 for %%i in ( %servercommands% ) do (
249 if "%hbase-command%"=="%%i" set servercommand=true
252 if "%servercommand%" == "true" (
253 set HBASE_OPTS=%HBASE_OPTS% %SERVER_GC_OPTS%
255 set HBASE_OPTS=%HBASE_OPTS% %CLIENT_GC_OPTS%
258 @rem If HBase is run as a windows service, configure logging
259 if defined service_entry (
260 set HBASE_LOG_PREFIX=hbase-%hbase-command%-%COMPUTERNAME%
261 set HBASE_LOGFILE=!HBASE_LOG_PREFIX!.log
262 if not defined HBASE_ROOT_LOGGER (
263 set HBASE_ROOT_LOGGER=INFO,DRFA
265 set HBASE_SECURITY_LOGGER=INFO,DRFAS
266 set loggc=!HBASE_LOG_DIR!\!HBASE_LOG_PREFIX!.gc
267 set loglog=!HBASE_LOG_DIR!\!HBASE_LOGFILE!
269 if "%HBASE_USE_GC_LOGFILE%" == "true" (
270 set HBASE_OPTS=%HBASE_OPTS% -Xloggc:"!loggc!"
275 @rem (1) for the commands which need jruby (see jruby-commands defined below)
276 @rem A. when JRUBY_HOME is defined
277 @rem CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME defined
278 @rem B. when JRUBY_HOME is not defined
279 @rem add jruby packaged with HBase to CLASSPATH
280 @rem (2) for other commands, do nothing
282 @rem check if the commmand needs jruby
283 set jruby-commands=shell org.jruby.Main
284 for %%i in ( %jruby-commands% ) do (
285 if "%hbase-command%"=="%%i" set jruby-needed=true
288 @rem the command needs jruby
289 if defined jruby-needed (
290 @rem JRUBY_HOME is defined
291 if defined JRUBY_HOME (
292 set CLASSPATH=%JRUBY_HOME%\lib\jruby.jar;%CLASSPATH%
293 set HBASE_OPTS=%HBASE_OPTS% -Djruby.home="%JRUBY_HOME%" -Djruby.lib="%JRUBY_HOME%\lib"
296 @rem JRUBY_HOME is not defined
297 if not defined JRUBY_HOME (
298 @rem in dev environment
299 if "%in_dev_env%"=="true" (
300 set cached_classpath_jruby_filename=%HBASE_HOME%\hbase-build-configuration\target\cached_classpath_jruby.txt
301 if not exist "!cached_classpath_jruby_filename!" (
302 echo "As this is a development environment, we need !cached_classpath_jruby_filename! to be generated from maven (command: mvn install -DskipTests)"
305 for /f "delims=" %%i in ('type "!cached_classpath_jruby_filename!"') do set CLASSPATH=%%i;%CLASSPATH%
308 @rem not in dev environment
309 if "%in_dev_env%"=="false" (
310 @rem add jruby packaged with HBase to CLASSPATH
311 set JRUBY_PACKAGED_WITH_HBASE=%HBASE_HOME%\lib\ruby\*
312 if defined jruby-needed (
313 set CLASSPATH=!JRUBY_PACKAGED_WITH_HBASE!;!CLASSPATH!
319 @rem Have JVM dump heap if we run out of memory. Files will be 'launch directory
'
320 @rem and are named like the following: java_pid21612.hprof. Apparently it does not
321 @rem 'cost
' to have this flag enabled. Its a 1.6 flag only. See:
322 @rem http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better
323 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.log.dir="%HBASE_LOG_DIR%"
324 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.log.file="%HBASE_LOGFILE%"
325 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.home.dir="%HBASE_HOME%"
326 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.id.str="%HBASE_IDENT_STRING%"
327 set HBASE_OPTS=%HBASE_OPTS% -XX:OnOutOfMemoryError="taskkill /F /PID %p"
329 @rem redirect java.util.logging to slf4j
330 set HBASE_OPTS=%HBASE_OPTS% -Djava.util.logging.config.class="org.apache.hadoop.hbase.logging.JulToSlf4jInitializer"
332 if not defined HBASE_ROOT_LOGGER (
333 set HBASE_ROOT_LOGGER=INFO,console
336 for /F "tokens=1,2 delims=," %%a in ("%HBASE_ROOT_LOGGER%") do (
337 set HBASE_ROOT_LOGGER_LEVEL=%%a
338 set HBASE_ROOT_LOGGER_APPENDER=%%b
341 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.root.logger.level="%HBASE_ROOT_LOGGER_LEVEL% -Dhbase.root.logger.appender="%HBASE_ROOT_LOGGER_APPENDER% "
343 if defined JAVA_LIBRARY_PATH (
344 set HBASE_OPTS=%HBASE_OPTS% -Djava.library.path="%JAVA_LIBRARY_PATH%"
347 rem Enable security logging on the master and regionserver only
348 if not defined HBASE_SECURITY_LOGGER (
349 set HBASE_SECURITY_LOGGER=INFO,NullAppender
350 if "%hbase-command%"=="master" (
351 set HBASE_SECURITY_LOGGER=INFO,DRFAS
353 if "%hbase-command%"=="regionserver" (
354 set HBASE_SECURITY_LOGGER=INFO,DRFAS
358 for /F "tokens=1,2 delims=," %%a in ("%HBASE_SECURITY_LOGGER%") do (
359 set HBASE_SECURITY_LOGGER_LEVEL=%%a
360 set HBASE_SECURITY_LOGGER_APPENDER=%%b
363 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.security.logger.level="%HBASE_SECURITY_LOGGER_LEVEL% -Dhbase.security.logger.appender="%HBASE_SECURITY_LOGGER_APPENDER%"
365 set HEAP_SETTINGS=%JAVA_HEAP_MAX% %JAVA_OFFHEAP_MAX%
366 set java_arguments=%HEAP_SETTINGS% %HBASE_OPTS% -classpath "%CLASSPATH%" %CLASS% %hbase-command-arguments%
368 if defined service_entry (
369 call :makeServiceXml %java_arguments%
371 call %JAVA% %java_arguments%
378 rem find the hbase ruby sources
379 if exist "%HBASE_HOME%\lib\ruby" (
380 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.ruby.sources="%HBASE_HOME%\lib\ruby"
382 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.ruby.sources="%HBASE_HOME%\hbase-shell\src\main\ruby"
384 set HBASE_OPTS=%HBASE_OPTS% %HBASE_SHELL_OPTS%
386 set CLASS=org.jruby.Main -X+O %JRUBY_OPTS% "%HBASE_HOME%\bin\hirb.rb"
390 set CLASS=org.apache.hadoop.hbase.master.HMaster
391 if NOT "%1"=="stop" (
392 set HBASE_OPTS=%HBASE_OPTS% %HBASE_MASTER_OPTS%
397 set CLASS=org.apache.hadoop.hbase.regionserver.HRegionServer
398 if NOT "%1"=="stop" (
399 set HBASE_OPTS=%HBASE_OPTS% %HBASE_REGIONSERVER_OPTS%
404 set CLASS=org.apache.hadoop.hbase.thrift.ThriftServer
405 if NOT "%1" == "stop" (
406 set HBASE_OPTS=%HBASE_OPTS% %HBASE_THRIFT_OPTS%
411 set CLASS=org.apache.hadoop.hbase.thrift2.ThriftServer
412 if NOT "%1" == "stop" (
413 set HBASE_OPTS=%HBASE_OPTS% %HBASE_THRIFT_OPTS%
418 set CLASS=org.apache.hadoop.hbase.rest.RESTServer
419 if NOT "%1"=="stop" (
420 set HBASE_OPTS=%HBASE_OPTS% %HBASE_REST_OPTS%
425 set CLASS=org.apache.hadoop.hbase.avro.AvroServer
426 if NOT "%1"== "stop" (
427 set HBASE_OPTS=%HBASE_OPTS% %HBASE_AVRO_OPTS%
432 set CLASS=org.apache.hadoop.hbase.zookeeper.HQuorumPeer
433 if NOT "%1"=="stop" (
434 set HBASE_OPTS=%HBASE_OPTS% %HBASE_ZOOKEEPER_OPTS%
439 set CLASS=org.apache.hadoop.hbase.util.HBaseFsck
443 set CLASS=org.apache.hadoop.hbase.wal.WALPrettyPrinter
447 set CLASS=org.apache.hadoop.hbase.io.hfile.HFile
451 set CLASS=org.apache.hadoop.hbase.zookeeper.ZKMainServer
452 set CLASSPATH=!CLASSPATH!;%HBASE_HOME%\lib\zkcli\*
456 set CLASS=org.apache.hadoop.hbase.util.MapreduceDependencyClasspathTool
462 @echo ^<id^>%hbase-command%^</id^>
463 @echo ^<name^>%hbase-command%^</name^>
464 @echo ^<description^>This service runs Isotope %hbase-command%^</description^>
465 @echo ^<executable^>%JAVA%^</executable^>
466 @echo ^<arguments^>%arguments%^</arguments^>
471 echo Usage: hbase [^<options^>] ^<command^> [^<args^>]
472 echo where ^<command^> an option from one of these categories::
474 echo --config DIR Configuration direction to use. Default: ./conf
475 echo --help or -h Print this help message
478 echo Some commands take arguments. Pass no args or -h for usage."
479 echo shell Run the HBase shell
480 echo hbck Run the hbase 'fsck
' tool
481 echo wal Write-ahead-log analyzer
482 echo hfile Store file analyzer
483 echo zkcli Run the ZooKeeper shell
484 echo master Run an HBase HMaster node
485 echo regionserver Run an HBase HRegionServer node
486 echo zookeeper Run a ZooKeeper server
487 echo rest Run an HBase REST server
488 echo thrift Run the HBase Thrift server
489 echo thrift2 Run the HBase Thrift2 server
490 echo classpath Dump hbase CLASSPATH
491 echo mapredcp Dump CLASSPATH entries required by mapreduce
492 echo version Print the version
493 echo CLASSNAME Run the class named CLASSNAME