PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/scripts/hcat_server_install.sh

#
Shell | 146 lines | 94 code | 24 blank | 28 comment | 34 complexity | c9f4b6f5a582e45057f84e7936957ffb MD5 | raw file
  1#!/bin/sh
  2
  3# Licensed to the Apache Software Foundation (ASF) under one
  4# or more contributor license agreements.  See the NOTICE file
  5# distributed with this work for additional information
  6# regarding copyright ownership.  The ASF licenses this file
  7# to you under the Apache License, Version 2.0 (the
  8# "License"); you may not use this file except in compliance
  9# with the License.  You may obtain a copy of the License at
 10#
 11# http://www.apache.org/licenses/LICENSE-2.0
 12#
 13# Unless required by applicable law or agreed to in writing, software
 14# distributed under the License is distributed on an "AS IS" BASIS,
 15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16# See the License for the specific language governing permissions and
 17# limitations under the License.
 18
 19# This script assumes that it is being run from the top level directory of the
 20# HCatalog distribution tarball
 21
 22function usage() {
 23    echo "Usage: $0 -r root -d dbroot -h hadoop_home -p server_port"
 24    echo "    root is the directory where you like to install the HCatalog server"
 25    echo "        /usr/local/hcat is suggested."
 26    echo "    dbroot is the directory where your mysql connector jar is located."
 27    echo "    hadoop_home is the directory of your Hadoop installation."
 28    echo "    server_port is the listening port of the HCatalog server"
 29    echo "    All paths must be absolute"
 30}
 31
 32dir_check=`head -1 NOTICE.txt`
 33if [ "${dir_check}" != "Apache HCatalog" ] ; then
 34    echo "This script must be run in the top level directory of your HCatalog" \
 35        "distribution."
 36    exit 1
 37fi
 38
 39root="unknown"
 40dbroot="unknown"
 41hadoop_home="unknown"
 42server_port="9080"
 43
 44while [ "${1}x" != "x" ] ; do
 45    if [ $1 == "-r" ] || [ $1 == "--root" ] ; then
 46        shift
 47        root=$1
 48        shift
 49    elif [ $1 == "-d" ] || [ $1 == "--dbroot" ] ; then
 50        shift
 51        dbroot=$1
 52        shift
 53    elif [ $1 == "-h" ] || [ $1 == "--hadoop" ] ; then
 54        shift
 55        hadoop_home=$1
 56        shift
 57    elif [ $1 == "-p" ] || [ $1 == "--port" ] ; then
 58        shift
 59        server_port=$1
 60        shift
 61    else
 62        echo "Unknown option $1"
 63        shift
 64    fi
 65
 66done
 67
 68for var in $root $dbroot $hadoop_home ; do
 69    if [ $var == "unknown" ] ; then
 70        usage
 71        exit 1
 72    fi
 73done
 74
 75# Make sure root and dbroot are absolute paths
 76
 77for var in $root $dbroot $hadoop_home ; do
 78    if [ ${var:0:1} != "/" ] ; then
 79        usage
 80        exit 1
 81    fi
 82done
 83
 84# Make sure root is writable and has the necessary directories
 85root_owner=`ls -ld $root | awk '{print $3}'`
 86if [ $root_owner != `whoami` ] ; then
 87    echo "You must run this as the user that will run HCatalog and that user" \
 88        "must own the root directory."
 89    exit 1
 90fi
 91
 92root_perms=`ls -ld $root | awk '{print $1}'`
 93if [ ${root_perms:0:4} != "drwx" ] ; then
 94    echo "Your root directory must be readable, writable, and executable by" \
 95        "its owner."
 96    exit 1
 97fi
 98
 99# Check that the required Mysql driver is in the dbroot
100mysql_jar=`ls ${dbroot}/mysql-connector-java-*.jar 2>/dev/null | grep mysql-connector-java`
101if [ "${mysql_jar}x" == "x" ] ; then
102    echo "The required jar file mysql-connector-java-version.jar is not in " \
103        "$dbroot or is not readable"
104    exit 1
105fi
106
107# Create the needed directories in root
108for dir in var conf var/log bin lib ; do
109    if [ ! -d $root/$dir ] ; then
110        mkdir $root/$dir
111    fi
112done
113
114# Move files into the appropriate directories
115for dir in bin conf lib ; do
116    for file in ./$dir/* ; do
117        cp -R $file $root/$dir
118    done
119done
120
121# Put the start and stop scripts into bin
122for file in hcat_server_start.sh hcat_server_stop.sh ; do
123	cp scripts/$file $root/bin
124done
125
126# Move the proto-hive-site.xml to hive-site.xml
127cp $root/conf/proto-hive-site.xml $root/conf/hive-site.xml
128
129# Set permissions on hive-site.xml to 700, since it will contain the password to the 
130# database
131chmod 700 $root/conf/hive-site.xml
132
133# Write out an environment file so that the start file can use it later
134cat > $root/conf/hcat-env.sh <<!!
135ROOT=$root
136DBROOT=$dbroot
137USER=`whoami`
138HADOOP_HOME=$hadoop_home
139export METASTORE_PORT=$server_port
140!!
141
142echo "Installation successful"
143
144
145
146