180 lines
6.3 KiB
Bash
Executable File
180 lines
6.3 KiB
Bash
Executable File
#!/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.
|
|
|
|
bin=`which $0`
|
|
bin=`dirname ${bin}`
|
|
bin=`cd "$bin"; pwd`
|
|
|
|
if [ -e "$bin/../libexec/hdfs-config.sh" ]; then
|
|
. "$bin"/../libexec/hdfs-config.sh
|
|
else
|
|
. "$bin/hdfs-config.sh"
|
|
fi
|
|
|
|
function print_usage(){
|
|
echo "Usage: hdfs [--config confdir] COMMAND"
|
|
echo " where COMMAND is one of:"
|
|
echo " namenode -format format the DFS filesystem"
|
|
echo " secondarynamenode run the DFS secondary namenode"
|
|
echo " namenode run the DFS namenode"
|
|
echo " datanode run a DFS datanode"
|
|
echo " dfsadmin run a DFS admin client"
|
|
echo " fsck run a DFS filesystem checking utility"
|
|
echo " balancer run a cluster balancing utility"
|
|
echo " jmxget get JMX exported values from NameNode or DataNode."
|
|
echo " oiv apply the offline fsimage viewer to an fsimage"
|
|
echo " oev apply the offline edits viewer to an edits file"
|
|
echo " fetchdt fetch a delegation token from the NameNode"
|
|
echo " getconf get config values from configuration"
|
|
echo " groups get the groups which users belong to"
|
|
echo " Use -help to see options"
|
|
echo ""
|
|
echo "Most commands print help when invoked w/o parameters."
|
|
}
|
|
|
|
if [ $# = 0 ]; then
|
|
print_usage
|
|
exit
|
|
fi
|
|
|
|
COMMAND=$1
|
|
shift
|
|
|
|
# Determine if we're starting a secure datanode, and if so, redefine appropriate variables
|
|
if [ "$COMMAND" == "datanode" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_SECURE_DN_USER" ]; then
|
|
if [ -n "$HADOOP_SECURE_DN_PID_DIR" ]; then
|
|
HADOOP_PID_DIR=$HADOOP_SECURE_DN_PID_DIR
|
|
fi
|
|
|
|
if [ -n "$HADOOP_SECURE_DN_LOG_DIR" ]; then
|
|
HADOOP_LOG_DIR=$HADOOP_SECURE_DN_LOG_DIR
|
|
fi
|
|
|
|
HADOOP_IDENT_STRING=$HADOOP_SECURE_DN_USER
|
|
starting_secure_dn="true"
|
|
fi
|
|
|
|
if [ "$COMMAND" = "namenode" ] ; then
|
|
CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
|
|
elif [ "$COMMAND" = "secondarynamenode" ] ; then
|
|
CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
|
|
elif [ "$COMMAND" = "datanode" ] ; then
|
|
CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode'
|
|
if [ "$starting_secure_dn" = "true" ]; then
|
|
HADOOP_OPTS="$HADOOP_OPTS -jvm server $HADOOP_DATANODE_OPTS"
|
|
else
|
|
HADOOP_OPTS="$HADOOP_OPTS -server $HADOOP_DATANODE_OPTS"
|
|
fi
|
|
elif [ "$COMMAND" = "dfs" ] ; then
|
|
CLASS=org.apache.hadoop.fs.FsShell
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
|
|
elif [ "$COMMAND" = "dfsadmin" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
|
|
elif [ "$COMMAND" = "fsck" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.DFSck
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
|
|
elif [ "$COMMAND" = "balancer" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
|
|
elif [ "$COMMAND" = "jmxget" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.JMXGet
|
|
elif [ "$COMMAND" = "oiv" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewer
|
|
elif [ "$COMMAND" = "oev" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer
|
|
elif [ "$COMMAND" = "fetchdt" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.DelegationTokenFetcher
|
|
elif [ "$COMMAND" = "getconf" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.GetConf
|
|
elif [ "$COMMAND" = "groups" ] ; then
|
|
CLASS=org.apache.hadoop.hdfs.tools.GetGroups
|
|
else
|
|
echo $COMMAND - invalid command
|
|
print_usage
|
|
exit
|
|
fi
|
|
|
|
# for developers, add hdfs classes to CLASSPATH
|
|
if [ -d "$HADOOP_HDFS_HOME/build/classes" ]; then
|
|
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/build/classes
|
|
fi
|
|
if [ -d "$HADOOP_HDFS_HOME/build/web/webapps" ]; then
|
|
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/build/web
|
|
fi
|
|
if [ -d "$HADOOP_HDFS_HOME/build/test/classes" ]; then
|
|
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/build/test/classes
|
|
fi
|
|
if [ -d "$HADOOP_HDFS_HOME/build/tools" ]; then
|
|
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/build/tools
|
|
fi
|
|
|
|
if [ -d "$HADOOP_HDFS_HOME/build/ivy/lib/hadoop-hdfs/common" ]; then
|
|
for f in $HADOOP_HDFS_HOME/build/ivy/lib/hadoop-hdfs/common/*.jar; do
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
done
|
|
fi
|
|
|
|
if [ -d "$HADOOP_HDFS_HOME/build/ivy/lib/hadoop-hdfs/hdfs" ]; then
|
|
for f in $HADOOP_HDFS_HOME/build/ivy/lib/hadoop-hdfs/hdfs/*.jar; do
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
done
|
|
fi
|
|
|
|
# for releases, add core hdfs jar & webapps to CLASSPATH
|
|
if [ -d "$HADOOP_PREFIX/share/hadoop/hdfs/webapps" ]; then
|
|
CLASSPATH=${CLASSPATH}:$HADOOP_PREFIX/share/hadoop/hdfs
|
|
fi
|
|
for f in $HADOOP_PREFIX/share/hadoop-hdfs/*.jar; do
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
done
|
|
|
|
# add libs to CLASSPATH
|
|
for f in $HADOOP_PREFIX/lib/*.jar; do
|
|
CLASSPATH=${CLASSPATH}:$f;
|
|
done
|
|
|
|
if $cygwin; then
|
|
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
|
|
fi
|
|
export CLASSPATH=$CLASSPATH
|
|
|
|
# Check to see if we should start a secure datanode
|
|
if [ "$starting_secure_dn" = "true" ]; then
|
|
if [ "$HADOOP_PID_DIR" = "" ]; then
|
|
HADOOP_SECURE_DN_PID="/tmp/hadoop_secure_dn.pid"
|
|
else
|
|
HADOOP_SECURE_DN_PID="$HADOOP_PID_DIR/hadoop_secure_dn.pid"
|
|
fi
|
|
|
|
exec "$HADOOP_PREFIX/bin/jsvc" \
|
|
-Dproc_$COMMAND -outfile "$HADOOP_LOG_DIR/jsvc.out" \
|
|
-errfile "$HADOOP_LOG_DIR/jsvc.err" \
|
|
-pidfile "$HADOOP_SECURE_DN_PID" \
|
|
-nodetach \
|
|
-user "$HADOOP_SECURE_DN_USER" \
|
|
-cp "$CLASSPATH" \
|
|
$JAVA_HEAP_MAX $HADOOP_OPTS \
|
|
org.apache.hadoop.hdfs.server.datanode.SecureDataNodeStarter "$@"
|
|
else
|
|
# run it
|
|
exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
|
|
fi
|
|
|