ramangrover29 | 116eb97 | 2013-02-20 20:47:35 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | # contributor license agreements. See the NOTICE file distributed with |
| 5 | # this work for additional information regarding copyright ownership. |
| 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | # (the "License"); you may not use this file except in compliance with |
| 8 | # the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | |
| 19 | # The Hadoop command script |
| 20 | # |
| 21 | # Environment Variables |
| 22 | # |
| 23 | # JAVA_HOME The java implementation to use. Overrides JAVA_HOME. |
| 24 | # |
| 25 | # HADOOP_CLASSPATH Extra Java CLASSPATH entries. |
| 26 | # |
| 27 | # HADOOP_HEAPSIZE The maximum amount of heap to use, in MB. |
| 28 | # Default is 1000. |
| 29 | # |
| 30 | # HADOOP_OPTS Extra Java runtime options. |
| 31 | # |
| 32 | # HADOOP_NAMENODE_OPTS These options are added to HADOOP_OPTS |
| 33 | # HADOOP_CLIENT_OPTS when the respective command is run. |
| 34 | # HADOOP_{COMMAND}_OPTS etc HADOOP_JT_OPTS applies to JobTracker |
| 35 | # for e.g. HADOOP_CLIENT_OPTS applies to |
| 36 | # more than one command (fs, dfs, fsck, |
| 37 | # dfsadmin etc) |
| 38 | # |
| 39 | # HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf. |
| 40 | # |
| 41 | # HADOOP_ROOT_LOGGER The root appender. Default is INFO,console |
| 42 | # |
| 43 | |
| 44 | bin=`dirname "$0"` |
| 45 | bin=`cd "$bin"; pwd` |
| 46 | |
| 47 | . "$bin"/hadoop-config.sh |
| 48 | |
| 49 | cygwin=false |
| 50 | case "`uname`" in |
| 51 | CYGWIN*) cygwin=true;; |
| 52 | esac |
| 53 | |
| 54 | # if no args specified, show usage |
| 55 | if [ $# = 0 ]; then |
| 56 | echo "Usage: hadoop [--config confdir] COMMAND" |
| 57 | echo "where COMMAND is one of:" |
| 58 | echo " namenode -format format the DFS filesystem" |
| 59 | echo " secondarynamenode run the DFS secondary namenode" |
| 60 | echo " namenode run the DFS namenode" |
| 61 | echo " datanode run a DFS datanode" |
| 62 | echo " dfsadmin run a DFS admin client" |
| 63 | echo " mradmin run a Map-Reduce admin client" |
| 64 | echo " fsck run a DFS filesystem checking utility" |
| 65 | echo " fs run a generic filesystem user client" |
| 66 | echo " balancer run a cluster balancing utility" |
| 67 | echo " jobtracker run the MapReduce job Tracker node" |
| 68 | echo " pipes run a Pipes job" |
| 69 | echo " tasktracker run a MapReduce task Tracker node" |
| 70 | echo " job manipulate MapReduce jobs" |
| 71 | echo " queue get information regarding JobQueues" |
| 72 | echo " version print the version" |
| 73 | echo " jar <jar> run a jar file" |
| 74 | echo " distcp <srcurl> <desturl> copy file or directories recursively" |
| 75 | echo " archive -archiveName NAME <src>* <dest> create a hadoop archive" |
| 76 | echo " daemonlog get/set the log level for each daemon" |
| 77 | echo " or" |
| 78 | echo " CLASSNAME run the class named CLASSNAME" |
| 79 | echo "Most commands print help when invoked w/o parameters." |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | # get arguments |
| 84 | COMMAND=$1 |
| 85 | shift |
| 86 | |
| 87 | if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then |
| 88 | . "${HADOOP_CONF_DIR}/hadoop-env.sh" |
| 89 | fi |
| 90 | |
| 91 | # some Java parameters |
| 92 | if [ "$JAVA_HOME" != "" ]; then |
| 93 | #echo "run java in $JAVA_HOME" |
| 94 | JAVA_HOME=$JAVA_HOME |
| 95 | fi |
| 96 | |
| 97 | if [ "$JAVA_HOME" = "" ]; then |
| 98 | echo "Error: JAVA_HOME is not set." |
| 99 | exit 1 |
| 100 | fi |
| 101 | |
| 102 | JAVA=$JAVA_HOME/bin/java |
| 103 | JAVA_HEAP_MAX=-Xmx1000m |
| 104 | |
| 105 | # check envvars which might override default args |
| 106 | if [ "$HADOOP_HEAPSIZE" != "" ]; then |
| 107 | #echo "run with heapsize $HADOOP_HEAPSIZE" |
| 108 | JAVA_HEAP_MAX="-Xmx""$HADOOP_HEAPSIZE""m" |
| 109 | #echo $JAVA_HEAP_MAX |
| 110 | fi |
| 111 | |
| 112 | # CLASSPATH initially contains $HADOOP_CONF_DIR |
| 113 | CLASSPATH=${HADOOP_CONF_DIR} |
| 114 | CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar |
| 115 | |
| 116 | # for developers, add Hadoop classes to CLASSPATH |
| 117 | if [ -d "$HADOOP_HOME/build/classes" ]; then |
| 118 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/classes |
| 119 | fi |
| 120 | if [ -d "$HADOOP_HOME/build/webapps" ]; then |
| 121 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build |
| 122 | fi |
| 123 | if [ -d "$HADOOP_HOME/build/test/classes" ]; then |
| 124 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/test/classes |
| 125 | fi |
| 126 | if [ -d "$HADOOP_HOME/build/tools" ]; then |
| 127 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/tools |
| 128 | fi |
| 129 | |
| 130 | # so that filenames w/ spaces are handled correctly in loops below |
| 131 | IFS= |
| 132 | |
| 133 | # for releases, add core hadoop jar & webapps to CLASSPATH |
| 134 | if [ -d "$HADOOP_HOME/webapps" ]; then |
| 135 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME |
| 136 | fi |
| 137 | for f in $HADOOP_HOME/hadoop-*-core.jar; do |
| 138 | CLASSPATH=${CLASSPATH}:$f; |
| 139 | done |
| 140 | |
| 141 | # add libs to CLASSPATH |
| 142 | for f in $HADOOP_HOME/lib/*.jar; do |
| 143 | CLASSPATH=${CLASSPATH}:$f; |
| 144 | done |
| 145 | |
| 146 | if [ -d "$HADOOP_HOME/build/ivy/lib/Hadoop/common" ]; then |
| 147 | for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/*.jar; do |
| 148 | CLASSPATH=${CLASSPATH}:$f; |
| 149 | done |
| 150 | fi |
| 151 | |
| 152 | for f in $HADOOP_HOME/lib/jsp-2.1/*.jar; do |
| 153 | CLASSPATH=${CLASSPATH}:$f; |
| 154 | done |
| 155 | |
| 156 | for f in $HADOOP_HOME/hadoop-*-tools.jar; do |
| 157 | TOOL_PATH=${TOOL_PATH}:$f; |
| 158 | done |
| 159 | for f in $HADOOP_HOME/build/hadoop-*-tools.jar; do |
| 160 | TOOL_PATH=${TOOL_PATH}:$f; |
| 161 | done |
| 162 | |
| 163 | # add user-specified CLASSPATH last |
| 164 | if [ "$HADOOP_CLASSPATH" != "" ]; then |
| 165 | CLASSPATH=${HADOOP_CLASSPATH}:${CLASSPATH} |
| 166 | fi |
| 167 | |
| 168 | # default log directory & file |
| 169 | if [ "$HADOOP_LOG_DIR" = "" ]; then |
| 170 | HADOOP_LOG_DIR="$HADOOP_HOME/logs" |
| 171 | fi |
| 172 | if [ "$HADOOP_LOGFILE" = "" ]; then |
| 173 | HADOOP_LOGFILE='hadoop.log' |
| 174 | fi |
| 175 | |
| 176 | # default policy file for service-level authorization |
| 177 | if [ "$HADOOP_POLICYFILE" = "" ]; then |
| 178 | HADOOP_POLICYFILE="hadoop-policy.xml" |
| 179 | fi |
| 180 | |
| 181 | # restore ordinary behaviour |
| 182 | unset IFS |
| 183 | |
| 184 | # figure out which class to run |
| 185 | if [ "$COMMAND" = "namenode" ] ; then |
| 186 | CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode' |
| 187 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS" |
| 188 | elif [ "$COMMAND" = "secondarynamenode" ] ; then |
| 189 | CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode' |
| 190 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS" |
| 191 | elif [ "$COMMAND" = "datanode" ] ; then |
| 192 | CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode' |
| 193 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_DATANODE_OPTS" |
| 194 | elif [ "$COMMAND" = "fs" ] ; then |
| 195 | CLASS=org.apache.hadoop.fs.FsShell |
| 196 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 197 | elif [ "$COMMAND" = "dfs" ] ; then |
| 198 | CLASS=org.apache.hadoop.fs.FsShell |
| 199 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 200 | elif [ "$COMMAND" = "dfsadmin" ] ; then |
| 201 | CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin |
| 202 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 203 | elif [ "$COMMAND" = "mradmin" ] ; then |
| 204 | CLASS=org.apache.hadoop.mapred.tools.MRAdmin |
| 205 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 206 | elif [ "$COMMAND" = "fsck" ] ; then |
| 207 | CLASS=org.apache.hadoop.hdfs.tools.DFSck |
| 208 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 209 | elif [ "$COMMAND" = "balancer" ] ; then |
| 210 | CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer |
| 211 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS" |
| 212 | elif [ "$COMMAND" = "jobtracker" ] ; then |
| 213 | CLASS=org.apache.hadoop.mapred.JobTracker |
| 214 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOBTRACKER_OPTS" |
| 215 | elif [ "$COMMAND" = "tasktracker" ] ; then |
| 216 | CLASS=org.apache.hadoop.mapred.TaskTracker |
| 217 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_TASKTRACKER_OPTS" |
| 218 | elif [ "$COMMAND" = "job" ] ; then |
| 219 | CLASS=org.apache.hadoop.mapred.JobClient |
| 220 | elif [ "$COMMAND" = "queue" ] ; then |
| 221 | CLASS=org.apache.hadoop.mapred.JobQueueClient |
| 222 | elif [ "$COMMAND" = "pipes" ] ; then |
| 223 | CLASS=org.apache.hadoop.mapred.pipes.Submitter |
| 224 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 225 | elif [ "$COMMAND" = "version" ] ; then |
| 226 | CLASS=org.apache.hadoop.util.VersionInfo |
| 227 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 228 | elif [ "$COMMAND" = "jar" ] ; then |
| 229 | CLASS=org.apache.hadoop.util.RunJar |
| 230 | elif [ "$COMMAND" = "distcp" ] ; then |
| 231 | CLASS=org.apache.hadoop.tools.DistCp |
| 232 | CLASSPATH=${CLASSPATH}:${TOOL_PATH} |
| 233 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 234 | elif [ "$COMMAND" = "daemonlog" ] ; then |
| 235 | CLASS=org.apache.hadoop.log.LogLevel |
| 236 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 237 | elif [ "$COMMAND" = "archive" ] ; then |
| 238 | CLASS=org.apache.hadoop.tools.HadoopArchives |
| 239 | CLASSPATH=${CLASSPATH}:${TOOL_PATH} |
| 240 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 241 | elif [ "$COMMAND" = "sampler" ] ; then |
| 242 | CLASS=org.apache.hadoop.mapred.lib.InputSampler |
| 243 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
| 244 | else |
| 245 | CLASS=$COMMAND |
| 246 | fi |
| 247 | |
| 248 | # cygwin path translation |
| 249 | if $cygwin; then |
| 250 | CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
| 251 | HADOOP_HOME=`cygpath -w "$HADOOP_HOME"` |
| 252 | HADOOP_LOG_DIR=`cygpath -w "$HADOOP_LOG_DIR"` |
| 253 | TOOL_PATH=`cygpath -p -w "$TOOL_PATH"` |
| 254 | fi |
| 255 | # setup 'java.library.path' for native-hadoop code if necessary |
| 256 | JAVA_LIBRARY_PATH='' |
| 257 | if [ -d "${HADOOP_HOME}/build/native" -o -d "${HADOOP_HOME}/lib/native" ]; then |
| 258 | JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} -Xmx32m org.apache.hadoop.util.PlatformName | sed -e "s/ /_/g"` |
| 259 | |
| 260 | if [ -d "$HADOOP_HOME/build/native" ]; then |
| 261 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/build/native/${JAVA_PLATFORM}/lib |
| 262 | fi |
| 263 | |
| 264 | if [ -d "${HADOOP_HOME}/lib/native" ]; then |
| 265 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
| 266 | JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HADOOP_HOME}/lib/native/${JAVA_PLATFORM} |
| 267 | else |
| 268 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/lib/native/${JAVA_PLATFORM} |
| 269 | fi |
| 270 | fi |
| 271 | fi |
| 272 | |
| 273 | # cygwin path translation |
| 274 | if $cygwin; then |
| 275 | JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"` |
| 276 | fi |
| 277 | |
| 278 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR" |
| 279 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE" |
| 280 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_HOME" |
| 281 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING" |
| 282 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}" |
| 283 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
| 284 | HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" |
| 285 | fi |
| 286 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.policy.file=$HADOOP_POLICYFILE" |
| 287 | |
| 288 | # run it |
| 289 | #echo "exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@"" |
| 290 | exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@" |