2007-08-22 22:19:18 -04:00
|
|
|
#! /usr/bin/env bash
|
2007-07-12 18:08:25 -04:00
|
|
|
#
|
|
|
|
#/**
|
|
|
|
# * Copyright 2007 The Apache Software Foundation
|
|
|
|
# *
|
|
|
|
# * 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.
|
|
|
|
# */
|
2007-05-07 15:58:53 -04:00
|
|
|
#
|
|
|
|
# The hbase command script. Based on the hadoop command script putting
|
|
|
|
# in hbase classes, libs and configurations ahead of hadoop's.
|
|
|
|
#
|
|
|
|
# TODO: Narrow the amount of duplicated code.
|
|
|
|
#
|
|
|
|
# Environment Variables:
|
|
|
|
#
|
|
|
|
# JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
|
|
|
|
#
|
2008-03-03 14:18:53 -05:00
|
|
|
# HBASE_CLASSPATH Extra Java CLASSPATH entries.
|
|
|
|
#
|
2007-05-07 15:58:53 -04:00
|
|
|
# HBASE_HEAPSIZE The maximum amount of heap to use, in MB.
|
|
|
|
# Default is 1000.
|
|
|
|
#
|
|
|
|
# HBASE_OPTS Extra Java runtime options.
|
|
|
|
#
|
|
|
|
# HBASE_CONF_DIR Alternate conf dir. Default is ${HBASE_HOME}/conf.
|
|
|
|
#
|
2008-02-05 01:15:44 -05:00
|
|
|
# HBASE_ROOT_LOGGER The root appender. Default is INFO,console
|
|
|
|
#
|
2010-05-18 00:12:04 -04:00
|
|
|
# MAVEN_HOME Where mvn is installed.
|
|
|
|
#
|
2007-05-07 15:58:53 -04:00
|
|
|
bin=`dirname "$0"`
|
|
|
|
bin=`cd "$bin"; pwd`
|
|
|
|
|
2008-02-05 15:09:24 -05:00
|
|
|
# This will set HBASE_HOME, etc.
|
2007-05-07 15:58:53 -04:00
|
|
|
. "$bin"/hbase-config.sh
|
|
|
|
|
|
|
|
cygwin=false
|
|
|
|
case "`uname`" in
|
|
|
|
CYGWIN*) cygwin=true;;
|
|
|
|
esac
|
|
|
|
|
2010-03-12 14:59:35 -05:00
|
|
|
# Detect if we are in hbase sources dir
|
|
|
|
in_sources_dir=false
|
|
|
|
if [ -f $HBASE_HOME/pom.xml ]; then
|
|
|
|
in_sources_dir=true
|
|
|
|
fi
|
|
|
|
|
2007-05-07 15:58:53 -04:00
|
|
|
# if no args specified, show usage
|
|
|
|
if [ $# = 0 ]; then
|
2008-02-05 15:09:24 -05:00
|
|
|
echo "Usage: hbase <command>"
|
2007-05-07 15:58:53 -04:00
|
|
|
echo "where <command> is one of:"
|
2008-05-30 15:19:46 -04:00
|
|
|
echo " shell run the HBase shell"
|
2010-03-12 14:59:35 -05:00
|
|
|
if $in_sources_dir; then
|
|
|
|
echo " shell-tests run the HBase shell tests"
|
|
|
|
fi
|
2008-05-30 15:19:46 -04:00
|
|
|
echo " master run an HBase HMaster node"
|
|
|
|
echo " regionserver run an HBase HRegionServer node"
|
|
|
|
echo " thrift run an HBase Thrift server"
|
2009-01-27 13:20:09 -05:00
|
|
|
echo " zookeeper run a Zookeeper server"
|
2008-01-22 22:24:32 -05:00
|
|
|
echo " migrate upgrade an hbase.rootdir"
|
2007-05-07 15:58:53 -04:00
|
|
|
echo " or"
|
|
|
|
echo " CLASSNAME run the class named CLASSNAME"
|
|
|
|
echo "Most commands print help when invoked w/o parameters."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# get arguments
|
|
|
|
COMMAND=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
JAVA=$JAVA_HOME/bin/java
|
|
|
|
JAVA_HEAP_MAX=-Xmx1000m
|
|
|
|
|
2010-05-18 00:12:04 -04:00
|
|
|
MVN="mvn"
|
|
|
|
if [ "$MAVEN_HOME" != "" ]; then
|
|
|
|
MVN=${MAVEN_HOME}/bin/mvn
|
|
|
|
fi
|
|
|
|
|
2007-05-07 15:58:53 -04:00
|
|
|
# check envvars which might override default args
|
|
|
|
if [ "$HBASE_HEAPSIZE" != "" ]; then
|
|
|
|
#echo "run with heapsize $HBASE_HEAPSIZE"
|
|
|
|
JAVA_HEAP_MAX="-Xmx""$HBASE_HEAPSIZE""m"
|
|
|
|
#echo $JAVA_HEAP_MAX
|
|
|
|
fi
|
|
|
|
|
2008-03-24 15:13:56 -04:00
|
|
|
# so that filenames w/ spaces are handled correctly in loops below
|
|
|
|
IFS=
|
|
|
|
|
2008-04-20 11:32:29 -04:00
|
|
|
# CLASSPATH initially contains $HBASE_CONF_DIR
|
2008-04-29 19:29:17 -04:00
|
|
|
CLASSPATH="${HBASE_CONF_DIR}"
|
2007-05-07 15:58:53 -04:00
|
|
|
CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
|
|
|
|
|
2010-05-18 00:12:04 -04:00
|
|
|
add_maven_deps_to_classpath() {
|
2010-05-20 05:02:18 -04:00
|
|
|
# The maven build dir is called 'target'
|
|
|
|
target="${HBASE_HOME}/target"
|
|
|
|
if [ ! -d "${HBASE_HOME}/target" ]
|
|
|
|
then
|
|
|
|
mkdir "${target}"
|
|
|
|
fi
|
|
|
|
# Need to generate classpath from maven pom. This is costly so generate it
|
|
|
|
# and cache it. Save the file into our target dir so a mvn clean will get
|
|
|
|
# clean it up and force us create a new one.
|
|
|
|
f="${target}/cached_classpath.txt"
|
|
|
|
if [ ! -f "${f}" ]
|
|
|
|
then
|
|
|
|
${MVN} -f "${HBASE_HOME}/pom.xml" dependency:build-classpath -Dmdep.outputFile="${f}" &> /dev/null
|
|
|
|
fi
|
2010-05-18 00:12:04 -04:00
|
|
|
CLASSPATH=${CLASSPATH}:`cat "${f}"`
|
|
|
|
}
|
2007-05-07 15:58:53 -04:00
|
|
|
|
2010-05-18 00:12:04 -04:00
|
|
|
add_maven_main_classes_to_classpath() {
|
2010-05-20 05:02:18 -04:00
|
|
|
if [ -d "$HBASE_HOME/target/classes" ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:$HBASE_HOME/target/classes
|
2010-05-18 00:12:04 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
add_maven_test_classes_to_classpath() {
|
|
|
|
# For developers, add hbase classes to CLASSPATH
|
2010-05-20 05:02:18 -04:00
|
|
|
f="$HBASE_HOME/target/test-classes"
|
2010-05-18 00:12:04 -04:00
|
|
|
if [ -d "${f}" ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:${f}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
add_maven_target_dir_to_classpath() {
|
|
|
|
# I never seem to *have* such a dir. -tlipcon
|
2010-03-04 12:43:05 -05:00
|
|
|
HBASE_VER=`grep '<version>' $HBASE_HOME/pom.xml | head -1 | sed 's/.*<version>\(.*\)<\/version>/\1/'`
|
|
|
|
MAVEN_TARGET_DIR=$HBASE_HOME/target/hbase-$HBASE_VER-bin/hbase-$HBASE_VER
|
|
|
|
if [ -d "$MAVEN_TARGET_DIR" ]; then
|
|
|
|
for f in $MAVEN_TARGET_DIR/*.jar $MAVEN_TARGET_DIR/lib/*.jar; do
|
|
|
|
if [ -f $f ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2010-05-18 00:12:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add maven target directory
|
|
|
|
if $in_sources_dir; then
|
|
|
|
add_maven_deps_to_classpath
|
|
|
|
add_maven_main_classes_to_classpath
|
|
|
|
add_maven_test_classes_to_classpath
|
2010-03-04 12:43:05 -05:00
|
|
|
fi
|
|
|
|
|
2009-05-21 15:23:22 -04:00
|
|
|
# For releases, add hbase & webapps to CLASSPATH
|
|
|
|
# Webapps must come first else it messes up Jetty
|
|
|
|
if [ -d "$HBASE_HOME/webapps" ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:$HBASE_HOME
|
|
|
|
fi
|
2008-02-05 01:15:44 -05:00
|
|
|
for f in $HBASE_HOME/hbase*.jar; do
|
2007-09-19 12:45:01 -04:00
|
|
|
if [ -f $f ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
|
|
fi
|
|
|
|
done
|
2007-05-07 15:58:53 -04:00
|
|
|
|
2008-05-14 15:06:52 -04:00
|
|
|
# Add libs to CLASSPATH
|
|
|
|
for f in $HBASE_HOME/lib/*.jar; do
|
|
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
|
|
done
|
|
|
|
|
2010-01-11 19:23:42 -05:00
|
|
|
# Add user-specified CLASSPATH last
|
2008-03-03 14:18:53 -05:00
|
|
|
if [ "$HBASE_CLASSPATH" != "" ]; then
|
|
|
|
CLASSPATH=${CLASSPATH}:${HBASE_CLASSPATH}
|
|
|
|
fi
|
2007-05-07 15:58:53 -04:00
|
|
|
|
|
|
|
# default log directory & file
|
2008-02-05 01:15:44 -05:00
|
|
|
if [ "$HBASE_LOG_DIR" = "" ]; then
|
|
|
|
HBASE_LOG_DIR="$HBASE_HOME/logs"
|
2007-05-07 15:58:53 -04:00
|
|
|
fi
|
2008-02-05 01:15:44 -05:00
|
|
|
if [ "$HBASE_LOGFILE" = "" ]; then
|
|
|
|
HBASE_LOGFILE='hbase.log'
|
2007-05-07 15:58:53 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# cygwin path translation
|
|
|
|
if $cygwin; then
|
|
|
|
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
|
|
|
|
HBASE_HOME=`cygpath -d "$HBASE_HOME"`
|
2008-02-05 15:09:24 -05:00
|
|
|
HBASE_LOG_DIR=`cygpath -d "$HBASE_LOG_DIR"`
|
2007-05-07 15:58:53 -04:00
|
|
|
fi
|
2008-04-14 15:34:11 -04:00
|
|
|
# setup 'java.library.path' for native-hadoop code if necessary
|
|
|
|
JAVA_LIBRARY_PATH=''
|
|
|
|
if [ -d "${HBASE_HOME}/build/native" -o -d "${HBASE_HOME}/lib/native" ]; then
|
|
|
|
JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e "s/ /_/g"`
|
|
|
|
|
|
|
|
if [ -d "$HBASE_HOME/build/native" ]; then
|
|
|
|
JAVA_LIBRARY_PATH=${HBASE_HOME}/build/native/${JAVA_PLATFORM}/lib
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "${HBASE_HOME}/lib/native" ]; then
|
|
|
|
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
|
|
|
|
JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HBASE_HOME}/lib/native/${JAVA_PLATFORM}
|
|
|
|
else
|
|
|
|
JAVA_LIBRARY_PATH=${HBASE_HOME}/lib/native/${JAVA_PLATFORM}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2007-05-07 15:58:53 -04:00
|
|
|
|
|
|
|
# cygwin path translation
|
|
|
|
if $cygwin; then
|
|
|
|
JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
|
|
|
|
fi
|
|
|
|
|
|
|
|
# restore ordinary behaviour
|
|
|
|
unset IFS
|
|
|
|
|
2009-03-18 16:46:18 -04:00
|
|
|
# figure out which class to run
|
|
|
|
if [ "$COMMAND" = "shell" ] ; then
|
|
|
|
CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb"
|
2010-03-12 14:59:35 -05:00
|
|
|
elif $in_sources_dir && [ "$COMMAND" = "shell-tests" ] ; then
|
|
|
|
# Finx maven build classpath
|
2010-05-18 00:12:04 -04:00
|
|
|
add_maven_deps_to_classpath
|
|
|
|
add_maven_main_classes_to_classpath
|
|
|
|
add_maven_test_classes_to_classpath
|
2010-03-12 14:59:35 -05:00
|
|
|
# Start the tests
|
2010-05-20 05:02:18 -04:00
|
|
|
CORESRC="${HBASE_HOME}/src"
|
2010-03-12 14:59:35 -05:00
|
|
|
CLASS="org.jruby.Main -I${CORESRC}/main/ruby -I${CORESRC}/test/ruby ${CORESRC}/test/ruby/tests_runner.rb"
|
2009-03-18 16:46:18 -04:00
|
|
|
elif [ "$COMMAND" = "master" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hbase.master.HMaster'
|
2010-01-22 14:26:09 -05:00
|
|
|
if [ "$1" != "stop" ] ; then
|
|
|
|
HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS"
|
|
|
|
fi
|
2009-03-18 16:46:18 -04:00
|
|
|
elif [ "$COMMAND" = "regionserver" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer'
|
2010-01-22 14:26:09 -05:00
|
|
|
if [ "$1" != "stop" ] ; then
|
|
|
|
HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS"
|
|
|
|
fi
|
2009-03-18 16:46:18 -04:00
|
|
|
elif [ "$COMMAND" = "thrift" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hbase.thrift.ThriftServer'
|
2010-01-22 14:26:09 -05:00
|
|
|
if [ "$1" != "stop" ] ; then
|
|
|
|
HBASE_OPTS="$HBASE_OPTS $HBASE_THRIFT_OPTS"
|
|
|
|
fi
|
2009-03-18 16:46:18 -04:00
|
|
|
elif [ "$COMMAND" = "migrate" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hbase.util.Migrate'
|
|
|
|
elif [ "$COMMAND" = "zookeeper" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hbase.zookeeper.HQuorumPeer'
|
2010-01-22 14:26:09 -05:00
|
|
|
if [ "$1" != "stop" ] ; then
|
|
|
|
HBASE_OPTS="$HBASE_OPTS $HBASE_ZOOKEEPER_OPTS"
|
|
|
|
fi
|
2007-05-07 15:58:53 -04:00
|
|
|
else
|
2009-03-18 16:46:18 -04:00
|
|
|
CLASS=$COMMAND
|
|
|
|
fi
|
2009-01-27 13:20:09 -05:00
|
|
|
|
2009-03-18 16:46:18 -04:00
|
|
|
# Have JVM dump heap if we run out of memory. Files will be 'launch directory'
|
|
|
|
# and are named like the following: java_pid21612.hprof. Apparently it doesn't
|
|
|
|
# 'cost' to have this flag enabled. Its a 1.6 flag only. See:
|
|
|
|
# http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Dhbase.log.dir=$HBASE_LOG_DIR"
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Dhbase.log.file=$HBASE_LOGFILE"
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Dhbase.home.dir=$HBASE_HOME"
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Dhbase.id.str=$HBASE_IDENT_STRING"
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Dhbase.root.logger=${HBASE_ROOT_LOGGER:-INFO,console}"
|
|
|
|
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
|
|
|
|
HBASE_OPTS="$HBASE_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
|
2009-01-27 13:20:09 -05:00
|
|
|
fi
|
2009-03-18 16:46:18 -04:00
|
|
|
|
|
|
|
# run it
|
|
|
|
exec "$JAVA" $JAVA_HEAP_MAX $HBASE_OPTS -classpath "$CLASSPATH" $CLASS "$@"
|