blob: 683e95dbd451f4bdf10902b39214447ea9f24daf [file] [log] [blame]
ramangrover29116eb972013-02-20 20:47:35 +00001#!/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
44bin=`dirname "$0"`
45bin=`cd "$bin"; pwd`
46
47. "$bin"/hadoop-config.sh
48
49cygwin=false
50case "`uname`" in
51CYGWIN*) cygwin=true;;
52esac
53
54# if no args specified, show usage
55if [ $# = 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
81fi
82
83# get arguments
84COMMAND=$1
85shift
86
87if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then
88 . "${HADOOP_CONF_DIR}/hadoop-env.sh"
89fi
90
91# some Java parameters
92if [ "$JAVA_HOME" != "" ]; then
93 #echo "run java in $JAVA_HOME"
94 JAVA_HOME=$JAVA_HOME
95fi
96
97if [ "$JAVA_HOME" = "" ]; then
98 echo "Error: JAVA_HOME is not set."
99 exit 1
100fi
101
102JAVA=$JAVA_HOME/bin/java
103JAVA_HEAP_MAX=-Xmx1000m
104
105# check envvars which might override default args
106if [ "$HADOOP_HEAPSIZE" != "" ]; then
107 #echo "run with heapsize $HADOOP_HEAPSIZE"
108 JAVA_HEAP_MAX="-Xmx""$HADOOP_HEAPSIZE""m"
109 #echo $JAVA_HEAP_MAX
110fi
111
112# CLASSPATH initially contains $HADOOP_CONF_DIR
113CLASSPATH=${HADOOP_CONF_DIR}
114CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
115
116# for developers, add Hadoop classes to CLASSPATH
117if [ -d "$HADOOP_HOME/build/classes" ]; then
118 CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/classes
119fi
120if [ -d "$HADOOP_HOME/build/webapps" ]; then
121 CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build
122fi
123if [ -d "$HADOOP_HOME/build/test/classes" ]; then
124 CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/test/classes
125fi
126if [ -d "$HADOOP_HOME/build/tools" ]; then
127 CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/tools
128fi
129
130# so that filenames w/ spaces are handled correctly in loops below
131IFS=
132
133# for releases, add core hadoop jar & webapps to CLASSPATH
134if [ -d "$HADOOP_HOME/webapps" ]; then
135 CLASSPATH=${CLASSPATH}:$HADOOP_HOME
136fi
137for f in $HADOOP_HOME/hadoop-*-core.jar; do
138 CLASSPATH=${CLASSPATH}:$f;
139done
140
141# add libs to CLASSPATH
142for f in $HADOOP_HOME/lib/*.jar; do
143 CLASSPATH=${CLASSPATH}:$f;
144done
145
146if [ -d "$HADOOP_HOME/build/ivy/lib/Hadoop/common" ]; then
147for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/*.jar; do
148 CLASSPATH=${CLASSPATH}:$f;
149done
150fi
151
152for f in $HADOOP_HOME/lib/jsp-2.1/*.jar; do
153 CLASSPATH=${CLASSPATH}:$f;
154done
155
156for f in $HADOOP_HOME/hadoop-*-tools.jar; do
157 TOOL_PATH=${TOOL_PATH}:$f;
158done
159for f in $HADOOP_HOME/build/hadoop-*-tools.jar; do
160 TOOL_PATH=${TOOL_PATH}:$f;
161done
162
163# add user-specified CLASSPATH last
164if [ "$HADOOP_CLASSPATH" != "" ]; then
165 CLASSPATH=${HADOOP_CLASSPATH}:${CLASSPATH}
166fi
167
168# default log directory & file
169if [ "$HADOOP_LOG_DIR" = "" ]; then
170 HADOOP_LOG_DIR="$HADOOP_HOME/logs"
171fi
172if [ "$HADOOP_LOGFILE" = "" ]; then
173 HADOOP_LOGFILE='hadoop.log'
174fi
175
176# default policy file for service-level authorization
177if [ "$HADOOP_POLICYFILE" = "" ]; then
178 HADOOP_POLICYFILE="hadoop-policy.xml"
179fi
180
181# restore ordinary behaviour
182unset IFS
183
184# figure out which class to run
185if [ "$COMMAND" = "namenode" ] ; then
186 CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
187 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
188elif [ "$COMMAND" = "secondarynamenode" ] ; then
189 CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
190 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
191elif [ "$COMMAND" = "datanode" ] ; then
192 CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode'
193 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_DATANODE_OPTS"
194elif [ "$COMMAND" = "fs" ] ; then
195 CLASS=org.apache.hadoop.fs.FsShell
196 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
197elif [ "$COMMAND" = "dfs" ] ; then
198 CLASS=org.apache.hadoop.fs.FsShell
199 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
200elif [ "$COMMAND" = "dfsadmin" ] ; then
201 CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin
202 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
203elif [ "$COMMAND" = "mradmin" ] ; then
204 CLASS=org.apache.hadoop.mapred.tools.MRAdmin
205 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
206elif [ "$COMMAND" = "fsck" ] ; then
207 CLASS=org.apache.hadoop.hdfs.tools.DFSck
208 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
209elif [ "$COMMAND" = "balancer" ] ; then
210 CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
211 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
212elif [ "$COMMAND" = "jobtracker" ] ; then
213 CLASS=org.apache.hadoop.mapred.JobTracker
214 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOBTRACKER_OPTS"
215elif [ "$COMMAND" = "tasktracker" ] ; then
216 CLASS=org.apache.hadoop.mapred.TaskTracker
217 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_TASKTRACKER_OPTS"
218elif [ "$COMMAND" = "job" ] ; then
219 CLASS=org.apache.hadoop.mapred.JobClient
220elif [ "$COMMAND" = "queue" ] ; then
221 CLASS=org.apache.hadoop.mapred.JobQueueClient
222elif [ "$COMMAND" = "pipes" ] ; then
223 CLASS=org.apache.hadoop.mapred.pipes.Submitter
224 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
225elif [ "$COMMAND" = "version" ] ; then
226 CLASS=org.apache.hadoop.util.VersionInfo
227 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
228elif [ "$COMMAND" = "jar" ] ; then
229 CLASS=org.apache.hadoop.util.RunJar
230elif [ "$COMMAND" = "distcp" ] ; then
231 CLASS=org.apache.hadoop.tools.DistCp
232 CLASSPATH=${CLASSPATH}:${TOOL_PATH}
233 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
234elif [ "$COMMAND" = "daemonlog" ] ; then
235 CLASS=org.apache.hadoop.log.LogLevel
236 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
237elif [ "$COMMAND" = "archive" ] ; then
238 CLASS=org.apache.hadoop.tools.HadoopArchives
239 CLASSPATH=${CLASSPATH}:${TOOL_PATH}
240 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
241elif [ "$COMMAND" = "sampler" ] ; then
242 CLASS=org.apache.hadoop.mapred.lib.InputSampler
243 HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
244else
245 CLASS=$COMMAND
246fi
247
248# cygwin path translation
249if $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"`
254fi
255# setup 'java.library.path' for native-hadoop code if necessary
256JAVA_LIBRARY_PATH=''
257if [ -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
271fi
272
273# cygwin path translation
274if $cygwin; then
275 JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
276fi
277
278HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
279HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE"
280HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_HOME"
281HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
282HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}"
283if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
284 HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
285fi
286HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.policy.file=$HADOOP_POLICYFILE"
287
288# run it
289#echo "exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@""
290exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@"