buyingyi | 98e9a9b | 2013-03-10 21:24:35 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | # contributor license agreements. See the NOTICE file distributed with |
| 5 | # this work for additional information regarding copyright ownership. |
| 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | # (the "License"); you may not use this file except in compliance with |
| 8 | # the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | cygwin=false |
| 19 | case "`uname`" in |
| 20 | CYGWIN*) cygwin=true;; |
| 21 | esac |
| 22 | |
| 23 | bin=`dirname "$0"` |
| 24 | bin=`cd "$bin"; pwd` |
| 25 | |
| 26 | . "$bin"/hive-config.sh |
| 27 | |
| 28 | SERVICE="" |
| 29 | HELP="" |
| 30 | while [ $# -gt 0 ]; do |
| 31 | case "$1" in |
| 32 | --service) |
| 33 | shift |
| 34 | SERVICE=$1 |
| 35 | shift |
| 36 | ;; |
| 37 | --rcfilecat) |
| 38 | SERVICE=rcfilecat |
| 39 | shift |
| 40 | ;; |
| 41 | --help) |
| 42 | HELP=_help |
| 43 | shift |
| 44 | ;; |
| 45 | *) |
| 46 | break |
| 47 | ;; |
| 48 | esac |
| 49 | done |
| 50 | |
| 51 | if [ "$SERVICE" = "" ] ; then |
| 52 | if [ "$HELP" = "_help" ] ; then |
| 53 | SERVICE="help" |
| 54 | else |
| 55 | SERVICE="cli" |
| 56 | fi |
| 57 | fi |
| 58 | |
| 59 | if [ -f "${HIVE_CONF_DIR}/hive-env.sh" ]; then |
| 60 | . "${HIVE_CONF_DIR}/hive-env.sh" |
| 61 | fi |
| 62 | |
| 63 | CLASSPATH="${HIVE_CONF_DIR}" |
| 64 | |
| 65 | HIVE_LIB=${HIVE_HOME}/lib |
| 66 | |
| 67 | # needed for execution |
| 68 | if [ ! -f ${HIVE_LIB}/hive-exec-*.jar ]; then |
| 69 | echo "Missing Hive Execution Jar: ${HIVE_LIB}/hive-exec-*.jar" |
| 70 | exit 1; |
| 71 | fi |
| 72 | |
| 73 | if [ ! -f ${HIVE_LIB}/hive-metastore-*.jar ]; then |
| 74 | echo "Missing Hive MetaStore Jar" |
| 75 | exit 2; |
| 76 | fi |
| 77 | |
| 78 | # cli specific code |
| 79 | if [ ! -f ${HIVE_LIB}/hive-cli-*.jar ]; then |
| 80 | echo "Missing Hive CLI Jar" |
| 81 | exit 3; |
| 82 | fi |
| 83 | |
buyingyi | 1ab3342 | 2013-03-13 06:59:36 +0000 | [diff] [blame] | 84 | CLASSPATH=${CLASSPATH}:${HIVE_LIB}/a-hive-path.jar |
buyingyi | 98e9a9b | 2013-03-10 21:24:35 +0000 | [diff] [blame] | 85 | |
| 86 | for f in ${HIVE_LIB}/*.jar; do |
| 87 | CLASSPATH=${CLASSPATH}:$f; |
| 88 | done |
| 89 | |
| 90 | # add the auxillary jars such as serdes |
| 91 | if [ -d "${HIVE_AUX_JARS_PATH}" ]; then |
| 92 | for f in ${HIVE_AUX_JARS_PATH}/*.jar; do |
| 93 | if [[ ! -f $f ]]; then |
| 94 | continue; |
| 95 | fi |
| 96 | if $cygwin; then |
| 97 | f=`cygpath -w "$f"` |
| 98 | fi |
| 99 | AUX_CLASSPATH=${AUX_CLASSPATH}:$f |
| 100 | if [ "${AUX_PARAM}" == "" ]; then |
| 101 | AUX_PARAM=file://$f |
| 102 | else |
| 103 | AUX_PARAM=${AUX_PARAM},file://$f; |
| 104 | fi |
| 105 | done |
| 106 | elif [ "${HIVE_AUX_JARS_PATH}" != "" ]; then |
| 107 | if $cygwin; then |
| 108 | HIVE_AUX_JARS_PATH=`echo $HIVE_AUX_JARS_PATH | sed 's/,/:/g'` |
| 109 | HIVE_AUX_JARS_PATH=`cygpath -p -w "$HIVE_AUX_JARS_PATH"` |
| 110 | HIVE_AUX_JARS_PATH=`echo $HIVE_AUX_JARS_PATH | sed 's/;/,/g'` |
| 111 | fi |
| 112 | AUX_CLASSPATH=${HIVE_AUX_JARS_PATH} |
| 113 | AUX_PARAM=file://${HIVE_AUX_JARS_PATH} |
| 114 | AUX_PARAM=`echo $AUX_PARAM | sed 's/,/,file:\/\//g'` |
| 115 | fi |
| 116 | |
| 117 | # adding jars from auxlib directory |
| 118 | for f in ${HIVE_HOME}/auxlib/*.jar; do |
| 119 | if [[ ! -f $f ]]; then |
| 120 | continue; |
| 121 | fi |
| 122 | if $cygwin; then |
| 123 | f=`cygpath -w "$f"` |
| 124 | fi |
| 125 | AUX_CLASSPATH=${AUX_CLASSPATH}:$f |
| 126 | if [ "${AUX_PARAM}" == "" ]; then |
| 127 | AUX_PARAM=file://$f |
| 128 | else |
| 129 | AUX_PARAM=${AUX_PARAM},file://$f; |
| 130 | fi |
| 131 | done |
| 132 | if $cygwin; then |
| 133 | CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
| 134 | CLASSPATH=${CLASSPATH};${AUX_CLASSPATH} |
| 135 | else |
| 136 | CLASSPATH=${CLASSPATH}:${AUX_CLASSPATH} |
| 137 | fi |
| 138 | |
| 139 | # pass classpath to hadoop |
| 140 | export HADOOP_CLASSPATH="${HADOOP_CLASSPATH}:${CLASSPATH}" |
| 141 | |
| 142 | # check for hadoop in the path |
| 143 | HADOOP_IN_PATH=`which hadoop 2>/dev/null` |
| 144 | if [ -f ${HADOOP_IN_PATH} ]; then |
| 145 | HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/.. |
| 146 | fi |
| 147 | # HADOOP_HOME env variable overrides hadoop in the path |
| 148 | HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR} |
| 149 | if [ "$HADOOP_HOME" == "" ]; then |
| 150 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 151 | exit 4; |
| 152 | fi |
| 153 | |
| 154 | HADOOP=$HADOOP_HOME/bin/hadoop |
| 155 | if [ ! -f ${HADOOP} ]; then |
| 156 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 157 | exit 4; |
| 158 | fi |
| 159 | |
| 160 | # Make sure we're using a compatible version of Hadoop |
| 161 | hadoop_version=$($HADOOP version | awk '{if (NR == 1) {print $2;}}'); |
| 162 | |
| 163 | # Save the regex to a var to workaround quoting incompatabilities |
| 164 | # between Bash 3.1 and 3.2 |
| 165 | hadoop_version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$" |
| 166 | |
| 167 | if [[ "$hadoop_version" =~ $hadoop_version_re ]]; then |
| 168 | hadoop_major_ver=${BASH_REMATCH[1]} |
| 169 | hadoop_minor_ver=${BASH_REMATCH[2]} |
| 170 | hadoop_patch_ver=${BASH_REMATCH[4]} |
| 171 | else |
| 172 | echo "Unable to determine Hadoop version information." |
| 173 | echo "'hadoop version' returned:" |
| 174 | echo `$HADOOP version` |
| 175 | exit 5 |
| 176 | fi |
| 177 | |
| 178 | if [ $hadoop_minor_ver -ne 20 -o $hadoop_patch_ver -eq 0 ]; then |
| 179 | echo "Hive requires Hadoop 0.20.x (x >= 1)." |
| 180 | echo "'hadoop version' returned:" |
| 181 | echo `$HADOOP version` |
| 182 | exit 6 |
| 183 | fi |
| 184 | |
| 185 | if [ "${AUX_PARAM}" != "" ]; then |
| 186 | HIVE_OPTS="$HIVE_OPTS -hiveconf hive.aux.jars.path=${AUX_PARAM}" |
| 187 | AUX_JARS_CMD_LINE="-libjars ${AUX_PARAM}" |
| 188 | fi |
| 189 | |
| 190 | SERVICE_LIST="" |
| 191 | |
| 192 | for i in "$bin"/ext/*.sh ; do |
| 193 | . $i |
| 194 | done |
| 195 | |
| 196 | for i in "$bin"/ext/util/*.sh ; do |
| 197 | . $i |
| 198 | done |
| 199 | |
| 200 | TORUN="" |
| 201 | for j in $SERVICE_LIST ; do |
| 202 | if [ "$j" = "$SERVICE" ] ; then |
| 203 | TORUN=${j}$HELP |
| 204 | fi |
| 205 | done |
| 206 | |
| 207 | if [ "$TORUN" = "" ] ; then |
| 208 | echo "Service $SERVICE not found" |
| 209 | echo "Available Services: $SERVICE_LIST" |
| 210 | exit 7 |
| 211 | else |
| 212 | $TORUN "$@" |
| 213 | fi |