buyingyi | 5df938f | 2013-03-24 07:20:08 +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 | |
| 19 | # The purpose of this script is to set warehouse's directories on HDFS |
| 20 | |
| 21 | DEFAULT_WAREHOUSE_DIR="/user/hive/warehouse" |
| 22 | DEFAULT_TMP_DIR="/tmp" |
| 23 | |
| 24 | WAREHOUSE_DIR=${DEFAULT_WAREHOUSE_DIR} |
| 25 | TMP_DIR=${DEFAULT_TMP_DIR} |
| 26 | HELP="" |
| 27 | while [ $# -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 |
| 49 | done |
| 50 | |
| 51 | if [ "$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 |
| 56 | fi |
| 57 | |
| 58 | |
| 59 | # check for hadoop in the path |
| 60 | HADOOP_IN_PATH=`which hadoop 2>/dev/null` |
| 61 | if [ -f ${HADOOP_IN_PATH} ]; then |
| 62 | HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/.. |
| 63 | fi |
| 64 | # HADOOP_HOME env variable overrides hadoop in the path |
| 65 | HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR} |
| 66 | if [ "$HADOOP_HOME" == "" ]; then |
| 67 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 68 | exit 4; |
| 69 | fi |
| 70 | |
| 71 | HADOOP_EXEC=$HADOOP_HOME/bin/hadoop |
| 72 | if [ ! -f ${HADOOP} ]; then |
| 73 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 74 | exit 4; |
| 75 | fi |
| 76 | |
| 77 | |
| 78 | # Ensure /tmp exist |
| 79 | $HADOOP_EXEC fs -test -d ${TMP_DIR} > /dev/null 2>&1 |
| 80 | if [ $? -ne 0 ] |
| 81 | then |
| 82 | echo "Creating directory [${TMP_DIR}]" |
| 83 | $HADOOP_EXEC fs -mkdir ${TMP_DIR} |
| 84 | fi |
| 85 | |
| 86 | echo "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 |
| 92 | if [ $? -ne 0 ] |
| 93 | then |
| 94 | echo "Creating directory [${WAREHOUSE_DIR}]" |
| 95 | $HADOOP_EXEC fs -mkdir ${WAREHOUSE_DIR} |
| 96 | fi |
| 97 | |
| 98 | echo "Setting writeable group rights for directory [${WAREHOUSE_DIR}]" |
| 99 | $HADOOP_EXEC fs -chmod g+w ${WAREHOUSE_DIR} |
| 100 | |
| 101 | echo "Initialization done." |
| 102 | echo |
| 103 | echo "Please, do not forget to set the following configuration properties in hive-site.xml:" |
| 104 | echo "hive.metastore.warehouse.dir=${WAREHOUSE_DIR}" |
| 105 | echo "hive.exec.scratchdir=${TMP_DIR}" |
| 106 | |
| 107 | exit 0 |