2011-06-12 22:00:51 +00:00
|
|
|
#!/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.
|
|
|
|
|
2013-03-05 22:37:04 +00:00
|
|
|
# Environment Variables
|
|
|
|
#
|
|
|
|
# JSVC_HOME home directory of jsvc binary. Required for starting secure
|
|
|
|
# datanode.
|
|
|
|
#
|
|
|
|
# JSVC_OUTFILE path to jsvc output file. Defaults to
|
|
|
|
# $HADOOP_LOG_DIR/jsvc.out.
|
|
|
|
#
|
|
|
|
# JSVC_ERRFILE path to jsvc error file. Defaults to $HADOOP_LOG_DIR/jsvc.err.
|
|
|
|
|
2011-06-12 22:00:51 +00:00
|
|
|
bin=`which $0`
|
|
|
|
bin=`dirname ${bin}`
|
2012-09-29 10:57:53 +00:00
|
|
|
bin=`cd "$bin" > /dev/null; pwd`
|
2011-06-12 22:00:51 +00:00
|
|
|
|
2011-11-18 00:53:46 +00:00
|
|
|
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
|
|
|
|
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
|
|
|
|
. $HADOOP_LIBEXEC_DIR/hdfs-config.sh
|
2011-06-12 22:00:51 +00:00
|
|
|
|
|
|
|
function print_usage(){
|
|
|
|
echo "Usage: hdfs [--config confdir] COMMAND"
|
|
|
|
echo " where COMMAND is one of:"
|
2012-02-18 15:25:11 +00:00
|
|
|
echo " dfs run a filesystem command on the file systems supported in Hadoop."
|
2011-06-12 22:00:51 +00:00
|
|
|
echo " namenode -format format the DFS filesystem"
|
|
|
|
echo " secondarynamenode run the DFS secondary namenode"
|
|
|
|
echo " namenode run the DFS namenode"
|
2012-07-20 00:25:50 +00:00
|
|
|
echo " journalnode run the DFS journalnode"
|
2012-04-03 00:59:02 +00:00
|
|
|
echo " zkfc run the ZK Failover Controller daemon"
|
2011-06-12 22:00:51 +00:00
|
|
|
echo " datanode run a DFS datanode"
|
|
|
|
echo " dfsadmin run a DFS admin client"
|
2012-01-30 02:52:27 +00:00
|
|
|
echo " haadmin run a DFS HA admin client"
|
2011-06-12 22:00:51 +00:00
|
|
|
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"
|
2014-05-14 01:15:16 +00:00
|
|
|
echo " oiv_legacy apply the offline fsimage viewer to an legacy fsimage"
|
2011-06-12 22:00:51 +00:00
|
|
|
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"
|
2013-03-18 11:36:59 +00:00
|
|
|
echo " snapshotDiff diff two snapshots of a directory or diff the"
|
|
|
|
echo " current directory contents with a snapshot"
|
|
|
|
echo " lsSnapshottableDir list all snapshottable dirs owned by the current user"
|
2011-06-12 22:00:51 +00:00
|
|
|
echo " Use -help to see options"
|
2013-08-07 22:21:42 +00:00
|
|
|
echo " portmap run a portmap service"
|
|
|
|
echo " nfs3 run an NFS version 3 gateway"
|
2013-09-12 03:55:10 +00:00
|
|
|
echo " cacheadmin configure the HDFS cache"
|
2014-06-25 17:42:03 +00:00
|
|
|
echo " crypto configure HDFS encryption zones"
|
2011-06-12 22:00:51 +00:00
|
|
|
echo ""
|
|
|
|
echo "Most commands print help when invoked w/o parameters."
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# = 0 ]; then
|
|
|
|
print_usage
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMMAND=$1
|
|
|
|
shift
|
|
|
|
|
2013-02-22 18:36:24 +00:00
|
|
|
case $COMMAND in
|
|
|
|
# usage flags
|
|
|
|
--help|-help|-h)
|
|
|
|
print_usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-06-12 22:00:51 +00:00
|
|
|
# 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
|
2012-05-11 03:15:54 +00:00
|
|
|
if [ -n "$JSVC_HOME" ]; 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
|
2013-03-04 19:34:15 +00:00
|
|
|
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
|
2012-05-11 03:15:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
HADOOP_IDENT_STRING=$HADOOP_SECURE_DN_USER
|
2013-03-04 19:34:15 +00:00
|
|
|
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
|
2012-05-11 03:15:54 +00:00
|
|
|
starting_secure_dn="true"
|
|
|
|
else
|
|
|
|
echo "It looks like you're trying to start a secure DN, but \$JSVC_HOME"\
|
|
|
|
"isn't set. Falling back to starting insecure DN."
|
2011-06-12 22:00:51 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-04-25 00:16:47 +00:00
|
|
|
# Determine if we're starting a privileged NFS daemon, and if so, redefine appropriate variables
|
|
|
|
if [ "$COMMAND" == "nfs3" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_PRIVILEGED_NFS_USER" ]; then
|
|
|
|
if [ -n "$JSVC_HOME" ]; then
|
|
|
|
if [ -n "$HADOOP_PRIVILEGED_NFS_PID_DIR" ]; then
|
|
|
|
HADOOP_PID_DIR=$HADOOP_PRIVILEGED_NFS_PID_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$HADOOP_PRIVILEGED_NFS_LOG_DIR" ]; then
|
|
|
|
HADOOP_LOG_DIR=$HADOOP_PRIVILEGED_NFS_LOG_DIR
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
HADOOP_IDENT_STRING=$HADOOP_PRIVILEGED_NFS_USER
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
|
|
|
|
starting_privileged_nfs="true"
|
|
|
|
else
|
|
|
|
echo "It looks like you're trying to start a privileged NFS server, but"\
|
|
|
|
"\$JSVC_HOME isn't set. Falling back to starting unprivileged NFS server."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-06-12 22:00:51 +00:00
|
|
|
if [ "$COMMAND" = "namenode" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
|
2012-04-03 00:59:02 +00:00
|
|
|
elif [ "$COMMAND" = "zkfc" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hdfs.tools.DFSZKFailoverController'
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_ZKFC_OPTS"
|
2011-06-12 22:00:51 +00:00
|
|
|
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
|
2012-07-20 00:25:50 +00:00
|
|
|
elif [ "$COMMAND" = "journalnode" ] ; then
|
|
|
|
CLASS='org.apache.hadoop.hdfs.qjournal.server.JournalNode'
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOURNALNODE_OPTS"
|
2011-06-12 22:00:51 +00:00
|
|
|
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"
|
2012-01-30 02:52:27 +00:00
|
|
|
elif [ "$COMMAND" = "haadmin" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.DFSHAAdmin
|
|
|
|
CLASSPATH=${CLASSPATH}:${TOOL_PATH}
|
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
|
2011-06-12 22:00:51 +00:00
|
|
|
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
|
2014-02-09 19:18:51 +00:00
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewerPB
|
2014-05-15 13:53:19 +00:00
|
|
|
elif [ "$COMMAND" = "oiv_legacy" ] ; then
|
2014-05-14 01:15:16 +00:00
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewer
|
2011-06-12 22:00:51 +00:00
|
|
|
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
|
2013-03-18 11:36:59 +00:00
|
|
|
elif [ "$COMMAND" = "snapshotDiff" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.snapshot.SnapshotDiff
|
|
|
|
elif [ "$COMMAND" = "lsSnapshottableDir" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.snapshot.LsSnapshottableDir
|
2013-08-07 22:21:42 +00:00
|
|
|
elif [ "$COMMAND" = "portmap" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.portmap.Portmap
|
2014-03-05 18:50:45 +00:00
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_PORTMAP_OPTS"
|
2013-08-07 22:21:42 +00:00
|
|
|
elif [ "$COMMAND" = "nfs3" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.nfs.nfs3.Nfs3
|
2014-03-05 18:50:45 +00:00
|
|
|
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NFS3_OPTS"
|
2013-09-12 03:55:10 +00:00
|
|
|
elif [ "$COMMAND" = "cacheadmin" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.CacheAdmin
|
2014-06-25 17:42:03 +00:00
|
|
|
elif [ "$COMMAND" = "crypto" ] ; then
|
|
|
|
CLASS=org.apache.hadoop.hdfs.tools.CryptoAdmin
|
2011-06-12 22:00:51 +00:00
|
|
|
else
|
2011-07-29 16:28:45 +00:00
|
|
|
CLASS="$COMMAND"
|
2011-06-12 22:00:51 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
export CLASSPATH=$CLASSPATH
|
|
|
|
|
2012-05-02 22:47:04 +00:00
|
|
|
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
|
2011-10-28 17:08:09 +00:00
|
|
|
|
2011-06-12 22:00:51 +00:00
|
|
|
# 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
|
2012-05-11 03:15:54 +00:00
|
|
|
HADOOP_SECURE_DN_PID="$HADOOP_PID_DIR/hadoop_secure_dn.pid"
|
2011-06-12 22:00:51 +00:00
|
|
|
fi
|
|
|
|
|
2012-03-13 03:38:57 +00:00
|
|
|
JSVC=$JSVC_HOME/jsvc
|
|
|
|
if [ ! -f $JSVC ]; then
|
2014-04-25 00:16:47 +00:00
|
|
|
echo "JSVC_HOME is not set correctly so jsvc cannot be found. jsvc is required to run secure datanodes. "
|
2012-03-13 03:38:57 +00:00
|
|
|
echo "Please download and install jsvc from http://archive.apache.org/dist/commons/daemon/binaries/ "\
|
|
|
|
"and set JSVC_HOME to the directory containing the jsvc binary."
|
|
|
|
exit
|
|
|
|
fi
|
2013-03-05 22:37:04 +00:00
|
|
|
|
|
|
|
if [[ ! $JSVC_OUTFILE ]]; then
|
|
|
|
JSVC_OUTFILE="$HADOOP_LOG_DIR/jsvc.out"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! $JSVC_ERRFILE ]]; then
|
|
|
|
JSVC_ERRFILE="$HADOOP_LOG_DIR/jsvc.err"
|
|
|
|
fi
|
|
|
|
|
2012-03-13 03:38:57 +00:00
|
|
|
exec "$JSVC" \
|
2013-03-05 22:37:04 +00:00
|
|
|
-Dproc_$COMMAND -outfile "$JSVC_OUTFILE" \
|
|
|
|
-errfile "$JSVC_ERRFILE" \
|
2011-06-12 22:00:51 +00:00
|
|
|
-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 "$@"
|
2014-04-25 00:16:47 +00:00
|
|
|
elif [ "$starting_privileged_nfs" = "true" ] ; then
|
|
|
|
if [ "$HADOOP_PID_DIR" = "" ]; then
|
|
|
|
HADOOP_PRIVILEGED_NFS_PID="/tmp/hadoop_privileged_nfs3.pid"
|
|
|
|
else
|
|
|
|
HADOOP_PRIVILEGED_NFS_PID="$HADOOP_PID_DIR/hadoop_privileged_nfs3.pid"
|
|
|
|
fi
|
|
|
|
|
|
|
|
JSVC=$JSVC_HOME/jsvc
|
|
|
|
if [ ! -f $JSVC ]; then
|
|
|
|
echo "JSVC_HOME is not set correctly so jsvc cannot be found. jsvc is required to run privileged NFS gateways. "
|
|
|
|
echo "Please download and install jsvc from http://archive.apache.org/dist/commons/daemon/binaries/ "\
|
|
|
|
"and set JSVC_HOME to the directory containing the jsvc binary."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! $JSVC_OUTFILE ]]; then
|
|
|
|
JSVC_OUTFILE="$HADOOP_LOG_DIR/nfs3_jsvc.out"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! $JSVC_ERRFILE ]]; then
|
|
|
|
JSVC_ERRFILE="$HADOOP_LOG_DIR/nfs3_jsvc.err"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec "$JSVC" \
|
|
|
|
-Dproc_$COMMAND -outfile "$JSVC_OUTFILE" \
|
|
|
|
-errfile "$JSVC_ERRFILE" \
|
|
|
|
-pidfile "$HADOOP_PRIVILEGED_NFS_PID" \
|
|
|
|
-nodetach \
|
|
|
|
-user "$HADOOP_PRIVILEGED_NFS_USER" \
|
|
|
|
-cp "$CLASSPATH" \
|
|
|
|
$JAVA_HEAP_MAX $HADOOP_OPTS \
|
|
|
|
org.apache.hadoop.hdfs.nfs.nfs3.PrivilegedNfsGatewayStarter "$@"
|
2011-06-12 22:00:51 +00:00
|
|
|
else
|
|
|
|
# run it
|
|
|
|
exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
|
|
|
|
fi
|
|
|
|
|