buyingyi | 98e9a9b | 2013-03-10 21:24:35 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Till Westmann | 276bbc2 | 2013-06-05 18:56:27 -0700 | [diff] [blame] | 2 | #/* |
| 3 | # Copyright 2009-2013 by The Regents of the University of California |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # you may obtain a copy of the License from |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | #*/ |
buyingyi | 98e9a9b | 2013-03-10 21:24:35 +0000 | [diff] [blame] | 16 | |
| 17 | # Licensed to the Apache Software Foundation (ASF) under one or more |
| 18 | # contributor license agreements. See the NOTICE file distributed with |
| 19 | # this work for additional information regarding copyright ownership. |
| 20 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
| 21 | # (the "License"); you may not use this file except in compliance with |
| 22 | # the License. You may obtain a copy of the License at |
| 23 | # |
| 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | # |
| 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | # See the License for the specific language governing permissions and |
| 30 | # limitations under the License. |
| 31 | |
| 32 | |
| 33 | # The purpose of this script is to set warehouse's directories on HDFS |
| 34 | |
| 35 | DEFAULT_WAREHOUSE_DIR="/user/hive/warehouse" |
| 36 | DEFAULT_TMP_DIR="/tmp" |
| 37 | |
| 38 | WAREHOUSE_DIR=${DEFAULT_WAREHOUSE_DIR} |
| 39 | TMP_DIR=${DEFAULT_TMP_DIR} |
| 40 | HELP="" |
| 41 | while [ $# -gt 0 ]; do |
| 42 | case "$1" in |
| 43 | --warehouse-dir) |
| 44 | shift |
| 45 | WAREHOUSE_DIR=$1 |
| 46 | shift |
| 47 | ;; |
| 48 | --tmp-dir) |
| 49 | shift |
| 50 | TMP_DIR=$1 |
| 51 | shift |
| 52 | ;; |
| 53 | --help) |
| 54 | HELP=_help |
| 55 | shift |
| 56 | ;; |
| 57 | *) |
| 58 | echo "Invalid parameter: $1" |
| 59 | HELP=_help |
| 60 | break |
| 61 | ;; |
| 62 | esac |
| 63 | done |
| 64 | |
| 65 | if [ "$HELP" = "_help" ] ; then |
| 66 | echo "Usage $0 [--warehouse-dir <Hive user>] [--tmp-dir <Tmp dir>]" |
| 67 | echo "Default value of warehouse directory is: [$DEFAULT_WAREHOUSE_DIR]" |
| 68 | echo "Default value of the temporary directory is: [$DEFAULT_TMP_DIR]" |
| 69 | exit -1 |
| 70 | fi |
| 71 | |
| 72 | |
| 73 | # check for hadoop in the path |
| 74 | HADOOP_IN_PATH=`which hadoop 2>/dev/null` |
| 75 | if [ -f ${HADOOP_IN_PATH} ]; then |
| 76 | HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/.. |
| 77 | fi |
| 78 | # HADOOP_HOME env variable overrides hadoop in the path |
| 79 | HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR} |
| 80 | if [ "$HADOOP_HOME" == "" ]; then |
| 81 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 82 | exit 4; |
| 83 | fi |
| 84 | |
| 85 | HADOOP_EXEC=$HADOOP_HOME/bin/hadoop |
| 86 | if [ ! -f ${HADOOP} ]; then |
| 87 | echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path"; |
| 88 | exit 4; |
| 89 | fi |
| 90 | |
| 91 | |
| 92 | # Ensure /tmp exist |
| 93 | $HADOOP_EXEC fs -test -d ${TMP_DIR} > /dev/null 2>&1 |
| 94 | if [ $? -ne 0 ] |
| 95 | then |
| 96 | echo "Creating directory [${TMP_DIR}]" |
| 97 | $HADOOP_EXEC fs -mkdir ${TMP_DIR} |
| 98 | fi |
| 99 | |
| 100 | echo "Setting writeable group rights for directory [${TMP_DIR}]" |
| 101 | $HADOOP_EXEC fs -chmod g+w ${TMP_DIR} |
| 102 | |
| 103 | |
| 104 | # Ensure warehouse dir exist |
| 105 | $HADOOP_EXEC fs -test -d ${WAREHOUSE_DIR} > /dev/null 2>&1 |
| 106 | if [ $? -ne 0 ] |
| 107 | then |
| 108 | echo "Creating directory [${WAREHOUSE_DIR}]" |
| 109 | $HADOOP_EXEC fs -mkdir ${WAREHOUSE_DIR} |
| 110 | fi |
| 111 | |
| 112 | echo "Setting writeable group rights for directory [${WAREHOUSE_DIR}]" |
| 113 | $HADOOP_EXEC fs -chmod g+w ${WAREHOUSE_DIR} |
| 114 | |
| 115 | echo "Initialization done." |
| 116 | echo |
| 117 | echo "Please, do not forget to set the following configuration properties in hive-site.xml:" |
| 118 | echo "hive.metastore.warehouse.dir=${WAREHOUSE_DIR}" |
| 119 | echo "hive.exec.scratchdir=${TMP_DIR}" |
| 120 | |
| 121 | exit 0 |