You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ey...@apache.org on 2011/10/04 19:48:27 UTC
svn commit: r1178877 - in /hadoop/common/branches/branch-0.20-security:
CHANGES.txt src/packages/hadoop-setup-applications.sh
Author: eyang
Date: Tue Oct 4 17:48:26 2011
New Revision: 1178877
URL: http://svn.apache.org/viewvc?rev=1178877&view=rev
Log:
HADOOP-7710. Added hadoop-setup-application.sh for creating
application directory (Arpit Gupta via Eric Yang)
Added:
hadoop/common/branches/branch-0.20-security/src/packages/hadoop-setup-applications.sh
Modified:
hadoop/common/branches/branch-0.20-security/CHANGES.txt
Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1178877&r1=1178876&r2=1178877&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Tue Oct 4 17:48:26 2011
@@ -380,6 +380,9 @@ Release 0.20.205.0 - unreleased
HDFS-2368. Move SPNEGO conf properties from hdfs-default.xml to
hdfs-site.xml. (szetszwo)
+ HADOOP-7710. Added hadoop-setup-application.sh for creating
+ application directory (Arpit Gupta via Eric Yang)
+
Release 0.20.204.0 - 2011-8-25
NEW FEATURES
Added: hadoop/common/branches/branch-0.20-security/src/packages/hadoop-setup-applications.sh
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/packages/hadoop-setup-applications.sh?rev=1178877&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/packages/hadoop-setup-applications.sh (added)
+++ hadoop/common/branches/branch-0.20-security/src/packages/hadoop-setup-applications.sh Tue Oct 4 17:48:26 2011
@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+this="${BASH_SOURCE-$0}"
+bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P)
+script="$(basename -- "$this")"
+this="$bin/$script"
+
+. "$bin"/../libexec/hadoop-config.sh
+
+usage() {
+ echo "
+usage: $0 <parameters>
+ Require parameter:
+ --config /etc/hadoop Location of Hadoop configuration file
+ --apps=<csl of apps:user hcat:hcat,hbase,hive:user> Apps you want to setup on hdfs
+ If user is not specified, app name
+ will be used as the user name as well
+ Optional parameters:
+ -h Display this message
+ --kerberos-realm=KERBEROS.EXAMPLE.COM Set Kerberos realm
+ --super-user=hdfs Set super user id
+ --super-user-keytab=/etc/security/keytabs/hdfs.keytab Set super user keytab location
+ "
+ exit 1
+}
+
+OPTS=$(getopt \
+ -n $0 \
+ -o '' \
+ -l 'kerberos-realm:' \
+ -l 'super-user:' \
+ -l 'super-user-keytab:' \
+ -l 'apps:' \
+ -o 'h' \
+ -- "$@")
+
+if [ $? != 0 ] ; then
+ usage
+ exit 1
+fi
+
+function setup_apps
+{
+ if [ -z $APPS ]
+ then
+ usage
+ break
+ fi
+
+ #if super user is not set default to hdfs
+ HADOOP_HDFS_USER=${HADOOP_HDFS_USER:-hdfs}
+
+ if [ ! "${KERBEROS_REALM}" = "" ]; then
+ # locate kinit cmd
+ if [ -e /etc/lsb-release ]; then
+ KINIT_CMD="/usr/bin/kinit -kt ${HDFS_USER_KEYTAB} ${HADOOP_HDFS_USER}"
+ else
+ KINIT_CMD="/usr/kerberos/bin/kinit -kt ${HDFS_USER_KEYTAB} ${HADOOP_HDFS_USER}"
+ fi
+ su -c "${KINIT_CMD}" ${HADOOP_HDFS_USER}
+ fi
+ #process each app
+ oldIFS=$IFS
+ IFS=','
+ for app in $APPS
+ do
+ IFS=":"
+ arr=($app)
+ app=${arr[0]}
+ user=${arr[1]}
+ IFS=','
+ #if user is empty, default it to app
+ if [ -z $user ]
+ then
+ user=$app
+ fi
+
+ path="/apps/${app}"
+
+ #create the dir
+ cmd="su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -mkdir ${path}' ${HADOOP_HDFS_USER}"
+ echo $cmd
+ eval $cmd
+
+ #make owner to be the app
+ cmd="su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -chown ${user} ${path}' ${HADOOP_HDFS_USER}"
+ echo $cmd
+ eval $cmd
+
+ if [ "$?" == "0" ]; then
+ echo "App directory has been setup: ${path}"
+ fi
+ done
+ IFS=$oldIFS
+}
+
+eval set -- "${OPTS}"
+while true; do
+ case "$1" in
+ --apps)
+ APPS=$2; shift 2
+ ;;
+ --kerberos-realm)
+ KERBEROS_REALM=$2; shift 2
+ ;;
+ --super-user)
+ HADOOP_HDFS_USER=$2; shift 2
+ ;;
+ --super-user-keytab)
+ HDFS_USER_KEYTAB=$2; shift 2
+ ;;
+ -h)
+ usage
+ ;;
+ --)
+ shift ; break
+ ;;
+ *)
+ echo "Unknown option: $1"
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+setup_apps