blob: f98f34089ca3b8697f3feaa662677cff46d18b74 [file] [log] [blame]
buyingyi98e9a9b2013-03-10 21:24:35 +00001#!/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
18cygwin=false
19case "`uname`" in
20 CYGWIN*) cygwin=true;;
21esac
22
23bin=`dirname "$0"`
24bin=`cd "$bin"; pwd`
25
26. "$bin"/hive-config.sh
27
28SERVICE=""
29HELP=""
30while [ $# -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
49done
50
51if [ "$SERVICE" = "" ] ; then
52 if [ "$HELP" = "_help" ] ; then
53 SERVICE="help"
54 else
55 SERVICE="cli"
56 fi
57fi
58
59if [ -f "${HIVE_CONF_DIR}/hive-env.sh" ]; then
60 . "${HIVE_CONF_DIR}/hive-env.sh"
61fi
62
63CLASSPATH="${HIVE_CONF_DIR}"
64
65HIVE_LIB=${HIVE_HOME}/lib
66
67# needed for execution
68if [ ! -f ${HIVE_LIB}/hive-exec-*.jar ]; then
69 echo "Missing Hive Execution Jar: ${HIVE_LIB}/hive-exec-*.jar"
70 exit 1;
71fi
72
73if [ ! -f ${HIVE_LIB}/hive-metastore-*.jar ]; then
74 echo "Missing Hive MetaStore Jar"
75 exit 2;
76fi
77
78# cli specific code
79if [ ! -f ${HIVE_LIB}/hive-cli-*.jar ]; then
80 echo "Missing Hive CLI Jar"
81 exit 3;
82fi
83
buyingyi1ab33422013-03-13 06:59:36 +000084CLASSPATH=${CLASSPATH}:${HIVE_LIB}/a-hive-path.jar
buyingyi98e9a9b2013-03-10 21:24:35 +000085
86for f in ${HIVE_LIB}/*.jar; do
87 CLASSPATH=${CLASSPATH}:$f;
88done
89
90# add the auxillary jars such as serdes
91if [ -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
106elif [ "${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'`
115fi
116
117# adding jars from auxlib directory
118for 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
131done
132if $cygwin; then
133 CLASSPATH=`cygpath -p -w "$CLASSPATH"`
134 CLASSPATH=${CLASSPATH};${AUX_CLASSPATH}
135else
136 CLASSPATH=${CLASSPATH}:${AUX_CLASSPATH}
137fi
138
139# pass classpath to hadoop
140export HADOOP_CLASSPATH="${HADOOP_CLASSPATH}:${CLASSPATH}"
141
142# check for hadoop in the path
143HADOOP_IN_PATH=`which hadoop 2>/dev/null`
144if [ -f ${HADOOP_IN_PATH} ]; then
145 HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/..
146fi
147# HADOOP_HOME env variable overrides hadoop in the path
148HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR}
149if [ "$HADOOP_HOME" == "" ]; then
150 echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
151 exit 4;
152fi
153
154HADOOP=$HADOOP_HOME/bin/hadoop
155if [ ! -f ${HADOOP} ]; then
156 echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
157 exit 4;
158fi
159
160# Make sure we're using a compatible version of Hadoop
161hadoop_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
165hadoop_version_re="^([[:digit:]]+)\.([[:digit:]]+)(\.([[:digit:]]+))?.*$"
166
167if [[ "$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]}
171else
172 echo "Unable to determine Hadoop version information."
173 echo "'hadoop version' returned:"
174 echo `$HADOOP version`
175 exit 5
176fi
177
178if [ $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
183fi
184
185if [ "${AUX_PARAM}" != "" ]; then
186 HIVE_OPTS="$HIVE_OPTS -hiveconf hive.aux.jars.path=${AUX_PARAM}"
187 AUX_JARS_CMD_LINE="-libjars ${AUX_PARAM}"
188fi
189
190SERVICE_LIST=""
191
192for i in "$bin"/ext/*.sh ; do
193 . $i
194done
195
196for i in "$bin"/ext/util/*.sh ; do
197 . $i
198done
199
200TORUN=""
201for j in $SERVICE_LIST ; do
202 if [ "$j" = "$SERVICE" ] ; then
203 TORUN=${j}$HELP
204 fi
205done
206
207if [ "$TORUN" = "" ] ; then
208 echo "Service $SERVICE not found"
209 echo "Available Services: $SERVICE_LIST"
210 exit 7
211else
212 $TORUN "$@"
213fi