PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/bin/init-hive-dfs.sh

#
Shell | 107 lines | 70 code | 17 blank | 20 comment | 10 complexity | 7934369a4985eec696dc2a4c3ea42753 MD5 | raw file
  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
 19# The purpose of this script is to set warehouse's directories on HDFS
 20
 21DEFAULT_WAREHOUSE_DIR="/user/hive/warehouse"
 22DEFAULT_TMP_DIR="/tmp"
 23
 24WAREHOUSE_DIR=${DEFAULT_WAREHOUSE_DIR}
 25TMP_DIR=${DEFAULT_TMP_DIR}
 26HELP=""
 27while [ $# -gt 0 ]; do
 28  case "$1" in
 29    --warehouse-dir)
 30      shift
 31      WAREHOUSE_DIR=$1
 32      shift
 33      ;;
 34    --tmp-dir)
 35      shift
 36      TMP_DIR=$1
 37      shift
 38      ;;
 39    --help)
 40      HELP=_help
 41      shift
 42      ;;
 43    *)
 44      echo "Invalid parameter: $1"
 45      HELP=_help
 46      break
 47      ;;
 48  esac
 49done
 50
 51if [ "$HELP" = "_help" ] ; then
 52  echo "Usage $0 [--warehouse-dir <Hive user>] [--tmp-dir <Tmp dir>]"
 53  echo "Default value of warehouse directory is: [$DEFAULT_WAREHOUSE_DIR]"
 54  echo "Default value of the temporary directory is: [$DEFAULT_TMP_DIR]"
 55  exit -1
 56fi
 57
 58
 59# check for hadoop in the path
 60HADOOP_IN_PATH=`which hadoop 2>/dev/null`
 61if [ -f ${HADOOP_IN_PATH} ]; then
 62  HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/..
 63fi
 64# HADOOP_HOME env variable overrides hadoop in the path
 65HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR}
 66if [ "$HADOOP_HOME" == "" ]; then
 67  echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
 68  exit 4;
 69fi
 70
 71HADOOP_EXEC=$HADOOP_HOME/bin/hadoop
 72if [ ! -f ${HADOOP} ]; then
 73  echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
 74  exit 4;
 75fi
 76
 77
 78# Ensure /tmp exist
 79$HADOOP_EXEC fs -test -d ${TMP_DIR} > /dev/null 2>&1
 80if [ $? -ne 0 ] 
 81then
 82  echo "Creating directory [${TMP_DIR}]"
 83  $HADOOP_EXEC fs -mkdir ${TMP_DIR}
 84fi
 85
 86echo "Setting writeable group rights for directory [${TMP_DIR}]"
 87$HADOOP_EXEC fs -chmod g+w ${TMP_DIR}
 88
 89
 90# Ensure warehouse dir exist
 91$HADOOP_EXEC fs -test -d ${WAREHOUSE_DIR} > /dev/null 2>&1
 92if [ $? -ne 0 ] 
 93then
 94  echo "Creating directory [${WAREHOUSE_DIR}]"
 95  $HADOOP_EXEC fs -mkdir ${WAREHOUSE_DIR}
 96fi
 97
 98echo "Setting writeable group rights for directory [${WAREHOUSE_DIR}]"
 99$HADOOP_EXEC fs -chmod g+w ${WAREHOUSE_DIR}
100
101echo "Initialization done."
102echo
103echo "Please, do not forget to set the following configuration properties in hive-site.xml:"
104echo "hive.metastore.warehouse.dir=${WAREHOUSE_DIR}"
105echo "hive.exec.scratchdir=${TMP_DIR}"
106
107exit 0