blob: b19ce8334a6b4c606ac767bb0e50377d5b4994b4 [file] [log] [blame]
buyingyi98e9a9b2013-03-10 21:24:35 +00001#!/usr/bin/env bash
Till Westmann276bbc22013-06-05 18:56:27 -07002#/*
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#*/
buyingyi98e9a9b2013-03-10 21:24:35 +000016
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
35DEFAULT_WAREHOUSE_DIR="/user/hive/warehouse"
36DEFAULT_TMP_DIR="/tmp"
37
38WAREHOUSE_DIR=${DEFAULT_WAREHOUSE_DIR}
39TMP_DIR=${DEFAULT_TMP_DIR}
40HELP=""
41while [ $# -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
63done
64
65if [ "$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
70fi
71
72
73# check for hadoop in the path
74HADOOP_IN_PATH=`which hadoop 2>/dev/null`
75if [ -f ${HADOOP_IN_PATH} ]; then
76 HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/..
77fi
78# HADOOP_HOME env variable overrides hadoop in the path
79HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR}
80if [ "$HADOOP_HOME" == "" ]; then
81 echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
82 exit 4;
83fi
84
85HADOOP_EXEC=$HADOOP_HOME/bin/hadoop
86if [ ! -f ${HADOOP} ]; then
87 echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
88 exit 4;
89fi
90
91
92# Ensure /tmp exist
93$HADOOP_EXEC fs -test -d ${TMP_DIR} > /dev/null 2>&1
94if [ $? -ne 0 ]
95then
96 echo "Creating directory [${TMP_DIR}]"
97 $HADOOP_EXEC fs -mkdir ${TMP_DIR}
98fi
99
100echo "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
106if [ $? -ne 0 ]
107then
108 echo "Creating directory [${WAREHOUSE_DIR}]"
109 $HADOOP_EXEC fs -mkdir ${WAREHOUSE_DIR}
110fi
111
112echo "Setting writeable group rights for directory [${WAREHOUSE_DIR}]"
113$HADOOP_EXEC fs -chmod g+w ${WAREHOUSE_DIR}
114
115echo "Initialization done."
116echo
117echo "Please, do not forget to set the following configuration properties in hive-site.xml:"
118echo "hive.metastore.warehouse.dir=${WAREHOUSE_DIR}"
119echo "hive.exec.scratchdir=${TMP_DIR}"
120
121exit 0