HBASE-17263 Netty based rpc server impl
[hbase.git] / bin / hbase.cmd
blob44cb9d3dbf009cb12347b5d9606da18db1c77671
1 @echo off
2 @rem/*
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
10 @rem *
11 @rem * http://www.apache.org/licenses/LICENSE-2.0
12 @rem *
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.
18 @rem */
19 @rem
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.
22 @rem
23 @rem TODO: Narrow the amount of duplicated code.
24 @rem
25 @rem Environment Variables:
26 @rem
27 @rem JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
28 @rem
29 @rem HBASE_CLASSPATH Extra Java CLASSPATH entries.
30 @rem
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).
34 @rem
35 @rem HBASE_OPTS Extra Java runtime options.
36 @rem
37 @rem HBASE_CONF_DIR Alternate conf dir. Default is ${HBASE_HOME}/conf.
38 @rem
39 @rem HBASE_ROOT_LOGGER The root appender. Default is INFO,console
40 @rem
41 @rem JRUBY_HOME JRuby path: $JRUBY_HOME\lib\jruby.jar should exist.
42 @rem Defaults to the jar packaged with HBase.
43 @rem
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
52 for %%i in (%0) do (
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%
62 rem This will set HBASE_HOME, etc.
63 set hbase-config-script=%HBASE_BIN_PATH%\hbase-config.cmd
64 call "%hbase-config-script%" %*
65 if "%1" == "--config" (
66 shift
67 shift
70 rem Detect if we are in hbase sources dir
71 set in_dev_env=false
73 if exist "%HBASE_HOME%\target" set in_dev_env=true
75 rem --service is an internal option. used by MSI setup to install HBase as a windows service
76 if "%1" == "--service" (
77 set service_entry=true
78 shift
81 set hbase-command=%1
82 shift
84 @rem if no args specified, show usage
85 if "%hbase-command%"=="" (
86 goto :print_usage
87 endlocal
88 goto :eof
91 set JAVA_HEAP_MAX=
92 set JAVA_OFFHEAP_MAX=
94 rem check envvars which might override default args
95 if defined HBASE_HEAPSIZE (
96 set JAVA_HEAP_MAX=-Xmx%HBASE_HEAPSIZE%m
99 if defined HBASE_OFFHEAPSIZE (
100 set JAVA_OFFHEAP_MAX=-XX:MaxDirectMemory=%HBASE_OFFHEAPSIZE%m
103 set CLASSPATH=%HBASE_CONF_DIR%;%JAVA_HOME%\lib\tools.jar
105 rem Add maven target directory
106 set cached_classpath_filename=%HBASE_HOME%\target\cached_classpath.txt
107 if "%in_dev_env%"=="true" (
109 rem adding maven main classes to classpath
110 for /f %%i in ('dir /b "%HBASE_HOME%\hbase-*"') do (
111 if exist %%i\target\classes set CLASSPATH=!CLASSPATH!;%%i\target\classes
114 rem adding maven test classes to classpath
115 rem For developers, add hbase classes to CLASSPATH
116 for /f %%i in ('dir /b "%HBASE_HOME%\hbase-*"') do (
117 if exist %%i\target\test-classes set CLASSPATH=!CLASSPATH!;%%i\target\test-classes
120 if not exist "%cached_classpath_filename%" (
121 echo "As this is a development environment, we need %cached_classpath_filename% to be generated from maven (command: mvn install -DskipTests)"
122 goto :eof
125 for /f "delims=" %%i in ('type "%cached_classpath_filename%"') do set CLASSPATH=%CLASSPATH%;%%i
128 @rem For releases add hbase webapps to CLASSPATH
129 @rem Webapps must come first else it messes up Jetty
130 if exist "%HBASE_HOME%\hbase-webapps" (
131 set CLASSPATH=%CLASSPATH%;%HBASE_HOME%
134 if exist "%HBASE_HOME%\target\hbase-webapps" (
135 set CLASSPATH=%CLASSPATH%;%HBASE_HOME%\target
138 for /F %%f in ('dir /b "%HBASE_HOME%\hbase*.jar" 2^>nul') do (
139 if not "%%f:~-11"=="sources.jar" (
140 set CLASSPATH=!CLASSPATH!;%HBASE_HOME%\%%f
144 @rem Add libs to CLASSPATH
145 if exist "%HBASE_HOME%\lib" (
146 set CLASSPATH=!CLASSPATH!;%HBASE_HOME%\lib\*
149 @rem Add user-specified CLASSPATH last
150 if defined HBASE_CLASSPATH (
151 set CLASSPATH=%CLASSPATH%;%HBASE_CLASSPATH%
154 @rem Default log directory and file
155 if not defined HBASE_LOG_DIR (
156 set HBASE_LOG_DIR=%HBASE_HOME%\logs
159 if not defined HBASE_LOGFILE (
160 set HBASE_LOGFILE=hbase.log
163 set JAVA_PLATFORM=
165 rem If avail, add Hadoop to the CLASSPATH and to the JAVA_LIBRARY_PATH
166 set PATH=%PATH%;"%HADOOP_HOME%\bin"
167 set HADOOP_IN_PATH=hadoop.cmd
169 if exist "%HADOOP_HOME%\bin\%HADOOP_IN_PATH%" (
170 set hadoopCpCommand=call %HADOOP_IN_PATH% classpath 2^>nul
171 for /f "eol= delims=" %%i in ('!hadoopCpCommand!') do set CLASSPATH_FROM_HADOOP=%%i
172 if defined CLASSPATH_FROM_HADOOP (
173 set CLASSPATH=%CLASSPATH%;!CLASSPATH_FROM_HADOOP!
175 set HADOOP_CLASSPATH=%CLASSPATH%
177 set hadoopJLPCommand=call %HADOOP_IN_PATH% org.apache.hadoop.hbase.util.GetJavaProperty java.library.path 2^>nul
178 for /f "eol= delims=" %%i in ('!hadoopJLPCommand!') do set HADOOP_JAVA_LIBRARY_PATH=%%i
179 if not defined JAVA_LIBRARY_PATH (
180 set JAVA_LIBRARY_PATH=!HADOOP_JAVA_LIBRARY_PATH!
181 ) else (
182 set JAVA_LIBRARY_PATH=%JAVA_LIBRARY_PATH%;!HADOOP_JAVA_LIBRARY_PATH!
186 if exist "%HBASE_HOME%\build\native" (
187 set platformCommand=call %JAVA% -classpath "%CLASSPATH%" org.apache.hadoop.util.PlatformName
188 for /f %%i in ('!platformCommand!') do set JAVA_PLATFORM=%%i
189 set _PATH_TO_APPEND=%HBASE_HOME%\build\native\!JAVA_PLATFORM!;%HBASE_HOME%\build\native\!JAVA_PLATFORM!\lib
190 if not defined JAVA_LIBRARY_PATH (
191 set JAVA_LIBRARY_PATH=!_PATH_TO_APPEND!
192 ) else (
193 set JAVA_LIBRARY_PATH=%JAVA_LIBRARY_PATH%;!_PATH_TO_APPEND!
197 rem This loop would set %hbase-command-arguments%
198 set _hbasearguments=
199 :MakeCmdArgsLoop
200 if [%1]==[] goto :EndLoop
202 if not defined _hbasearguments (
203 set _hbasearguments=%1
204 ) else (
205 set _hbasearguments=!_hbasearguments! %1
207 shift
208 goto :MakeCmdArgsLoop
209 :EndLoop
211 set hbase-command-arguments=%_hbasearguments%
213 @rem figure out which class to run
214 set corecommands=shell master regionserver thrift thrift2 rest avro hlog wal hbck hfile zookeeper zkcli mapredcp
215 for %%i in ( %corecommands% ) do (
216 if "%hbase-command%"=="%%i" set corecommand=true
219 if defined corecommand (
220 call :%hbase-command% %hbase-command-arguments%
221 ) else (
222 if "%hbase-command%" == "classpath" (
223 echo %CLASSPATH%
224 goto :eof
226 if "%hbase-command%" == "version" (
227 set CLASS=org.apache.hadoop.hbase.util.VersionInfo
228 ) else (
229 set CLASS=%hbase-command%
233 if not defined HBASE_IDENT_STRING (
234 set HBASE_IDENT_STRING=%USERNAME%
237 @rem Set the right GC options based on the what we are running
238 set servercommands=master regionserver thrift thrift2 rest avro zookeeper
239 for %%i in ( %servercommands% ) do (
240 if "%hbase-command%"=="%%i" set servercommand=true
243 if "%servercommand%" == "true" (
244 set HBASE_OPTS=%HBASE_OPTS% %SERVER_GC_OPTS%
245 ) else (
246 set HBASE_OPTS=%HBASE_OPTS% %CLIENT_GC_OPTS%
249 @rem If HBase is run as a windows service, configure logging
250 if defined service_entry (
251 set HBASE_LOG_PREFIX=hbase-%hbase-command%-%COMPUTERNAME%
252 set HBASE_LOGFILE=!HBASE_LOG_PREFIX!.log
253 if not defined HBASE_ROOT_LOGGER (
254 set HBASE_ROOT_LOGGER=INFO,DRFA
256 set HBASE_SECURITY_LOGGER=INFO,DRFAS
257 set loggc=!HBASE_LOG_DIR!\!HBASE_LOG_PREFIX!.gc
258 set loglog=!HBASE_LOG_DIR!\!HBASE_LOGFILE!
260 if "%HBASE_USE_GC_LOGFILE%" == "true" (
261 set HBASE_OPTS=%HBASE_OPTS% -Xloggc:"!loggc!"
265 @rem for jruby
266 @rem (1) when JRUBY_HOME is defined
267 @rem for all commands, CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME specified
268 @rem (2) when JRUBY_HOME is not defined
269 @rem A. for jruby-commands defined below, add JRUBY_PACKAGED_WITH_HBASE into CLASSPATH
270 @rem B. for other commands, do nothing
272 @rem JRUBY_HOME is defined
273 if defined JRUBY_HOME (
274 set CLASSPATH=%CLASSPATH%;%JRUBY_HOME%\lib\jruby.jar
275 set HBASE_OPTS=%HBASE_OPTS% -Djruby.home="%JRUBY_HOME%" -Djruby.lib="%JRUBY_HOME%\lib"
278 @rem JRUBY_HOME is not defined
279 if not defined JRUBY_HOME (
280 @rem check if the commmand needs jruby
281 set jruby-commands=shell org.jruby.Main
282 for %%i in ( !jruby-commands! ) do (
283 if "%hbase-command%"=="%%i" set jruby-needed=true
286 @rem add JRUBY_PACKAGED_WITH_HBASE to CLASSPATH if jruby is needed
287 set JRUBY_PACKAGED_WITH_HBASE=%HBASE_HOME%\lib\ruby\*
288 if defined jruby-needed (
289 set CLASSPATH=!JRUBY_PACKAGED_WITH_HBASE!;!CLASSPATH!
293 @rem Have JVM dump heap if we run out of memory. Files will be 'launch directory'
294 @rem and are named like the following: java_pid21612.hprof. Apparently it does not
295 @rem 'cost' to have this flag enabled. Its a 1.6 flag only. See:
296 @rem http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better
297 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.log.dir="%HBASE_LOG_DIR%"
298 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.log.file="%HBASE_LOGFILE%"
299 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.home.dir="%HBASE_HOME%"
300 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.id.str="%HBASE_IDENT_STRING%"
301 set HBASE_OPTS=%HBASE_OPTS% -XX:OnOutOfMemoryError="taskkill /F /PID %p"
303 if not defined HBASE_ROOT_LOGGER (
304 set HBASE_ROOT_LOGGER=INFO,console
306 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.root.logger="%HBASE_ROOT_LOGGER%"
308 if defined JAVA_LIBRARY_PATH (
309 set HBASE_OPTS=%HBASE_OPTS% -Djava.library.path="%JAVA_LIBRARY_PATH%"
312 rem Enable security logging on the master and regionserver only
313 if not defined HBASE_SECURITY_LOGGER (
314 set HBASE_SECURITY_LOGGER=INFO,NullAppender
315 if "%hbase-command%"=="master" (
316 set HBASE_SECURITY_LOGGER=INFO,DRFAS
318 if "%hbase-command%"=="regionserver" (
319 set HBASE_SECURITY_LOGGER=INFO,DRFAS
322 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.security.logger="%HBASE_SECURITY_LOGGER%"
324 set HEAP_SETTINGS=%JAVA_HEAP_MAX% %JAVA_OFFHEAP_MAX%
325 set java_arguments=%HEAP_SETTINGS% %HBASE_OPTS% -classpath "%CLASSPATH%" %CLASS% %hbase-command-arguments%
327 if defined service_entry (
328 call :makeServiceXml %java_arguments%
329 ) else (
330 call %JAVA% %java_arguments%
333 endlocal
334 goto :eof
336 :shell
337 rem find the hbase ruby sources
338 if exist "%HBASE_HOME%\lib\ruby" (
339 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.ruby.sources="%HBASE_HOME%\lib\ruby"
340 ) else (
341 set HBASE_OPTS=%HBASE_OPTS% -Dhbase.ruby.sources="%HBASE_HOME%\hbase-shell\src\main\ruby"
343 set HBASE_OPTS=%HBASE_OPTS% %HBASE_SHELL_OPTS%
345 set CLASS=org.jruby.Main -X+O %JRUBY_OPTS% "%HBASE_HOME%\bin\hirb.rb"
346 goto :eof
348 :master
349 set CLASS=org.apache.hadoop.hbase.master.HMaster
350 if NOT "%1"=="stop" (
351 set HBASE_OPTS=%HBASE_OPTS% %HBASE_MASTER_OPTS%
353 goto :eof
355 :regionserver
356 set CLASS=org.apache.hadoop.hbase.regionserver.HRegionServer
357 if NOT "%1"=="stop" (
358 set HBASE_OPTS=%HBASE_OPTS% %HBASE_REGIONSERVER_OPTS%
360 goto :eof
362 :thrift
363 set CLASS=org.apache.hadoop.hbase.thrift.ThriftServer
364 if NOT "%1" == "stop" (
365 set HBASE_OPTS=%HBASE_OPTS% %HBASE_THRIFT_OPTS%
367 goto :eof
369 :thrift2
370 set CLASS=org.apache.hadoop.hbase.thrift2.ThriftServer
371 if NOT "%1" == "stop" (
372 set HBASE_OPTS=%HBASE_OPTS% %HBASE_THRIFT_OPTS%
374 goto :eof
376 :rest
377 set CLASS=org.apache.hadoop.hbase.rest.RESTServer
378 if NOT "%1"=="stop" (
379 set HBASE_OPTS=%HBASE_OPTS% %HBASE_REST_OPTS%
381 goto :eof
383 :avro
384 set CLASS=org.apache.hadoop.hbase.avro.AvroServer
385 if NOT "%1"== "stop" (
386 set HBASE_OPTS=%HBASE_OPTS% %HBASE_AVRO_OPTS%
388 goto :eof
390 :zookeeper
391 set CLASS=org.apache.hadoop.hbase.zookeeper.HQuorumPeer
392 if NOT "%1"=="stop" (
393 set HBASE_OPTS=%HBASE_OPTS% %HBASE_ZOOKEEPER_OPTS%
395 goto :eof
397 :hbck
398 set CLASS=org.apache.hadoop.hbase.util.HBaseFsck
399 goto :eof
401 @rem TODO remove older 'hlog' command
402 :hlog
403 set CLASS=org.apache.hadoop.hbase.wal.WALPrettyPrinter
404 goto :eof
406 :wal
407 set CLASS=org.apache.hadoop.hbase.wal.WALPrettyPrinter
408 goto :eof
410 :hfile
411 set CLASS=org.apache.hadoop.hbase.io.hfile.HFile
412 goto :eof
414 :zkcli
415 set CLASS=org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer
416 goto :eof
418 :mapredcp
419 set CLASS=org.apache.hadoop.hbase.util.MapreduceDependencyClasspathTool
420 goto :eof
422 :makeServiceXml
423 set arguments=%*
424 @echo ^<service^>
425 @echo ^<id^>%hbase-command%^</id^>
426 @echo ^<name^>%hbase-command%^</name^>
427 @echo ^<description^>This service runs Isotope %hbase-command%^</description^>
428 @echo ^<executable^>%JAVA%^</executable^>
429 @echo ^<arguments^>%arguments%^</arguments^>
430 @echo ^</service^>
431 goto :eof
433 :print_usage
434 echo Usage: hbase [^<options^>] ^<command^> [^<args^>]
435 echo where ^<command^> an option from one of these categories::
436 echo Options:
437 echo --config DIR Configuration direction to use. Default: ./conf
438 echo.
439 echo Commands:
440 echo Some commands take arguments. Pass no args or -h for usage."
441 echo shell Run the HBase shell
442 echo hbck Run the hbase 'fsck' tool
443 echo wal Write-ahead-log analyzer
444 echo hfile Store file analyzer
445 echo zkcli Run the ZooKeeper shell
446 echo master Run an HBase HMaster node
447 echo regionserver Run an HBase HRegionServer node
448 echo zookeeper Run a ZooKeeper server
449 echo rest Run an HBase REST server
450 echo thrift Run the HBase Thrift server
451 echo thrift2 Run the HBase Thrift2 server
452 echo classpath Dump hbase CLASSPATH
453 echo mapredcp Dump CLASSPATH entries required by mapreduce
454 echo version Print the version
455 echo CLASSNAME Run the class named CLASSNAME
456 goto :eof