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 " fsck run a DFS filesystem checking utility" |
---|
64 | echo " fs run a generic filesystem user client" |
---|
65 | echo " balancer run a cluster balancing utility" |
---|
66 | echo " jobtracker run the MapReduce job Tracker node" |
---|
67 | echo " pipes run a Pipes job" |
---|
68 | echo " tasktracker run a MapReduce task Tracker node" |
---|
69 | echo " job manipulate MapReduce jobs" |
---|
70 | echo " queue get information regarding JobQueues" |
---|
71 | echo " version print the version" |
---|
72 | echo " jar <jar> run a jar file" |
---|
73 | echo " distcp <srcurl> <desturl> copy file or directories recursively" |
---|
74 | echo " archive -archiveName NAME <src>* <dest> create a hadoop archive" |
---|
75 | echo " daemonlog get/set the log level for each daemon" |
---|
76 | echo " or" |
---|
77 | echo " CLASSNAME run the class named CLASSNAME" |
---|
78 | echo "Most commands print help when invoked w/o parameters." |
---|
79 | exit 1 |
---|
80 | fi |
---|
81 | |
---|
82 | # get arguments |
---|
83 | COMMAND=$1 |
---|
84 | shift |
---|
85 | |
---|
86 | if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then |
---|
87 | . "${HADOOP_CONF_DIR}/hadoop-env.sh" |
---|
88 | fi |
---|
89 | |
---|
90 | # some Java parameters |
---|
91 | if [ "$JAVA_HOME" != "" ]; then |
---|
92 | #echo "run java in $JAVA_HOME" |
---|
93 | JAVA_HOME=$JAVA_HOME |
---|
94 | fi |
---|
95 | |
---|
96 | if [ "$JAVA_HOME" = "" ]; then |
---|
97 | echo "Error: JAVA_HOME is not set." |
---|
98 | exit 1 |
---|
99 | fi |
---|
100 | |
---|
101 | JAVA=$JAVA_HOME/bin/java |
---|
102 | JAVA_HEAP_MAX=-Xmx1000m |
---|
103 | |
---|
104 | # check envvars which might override default args |
---|
105 | if [ "$HADOOP_HEAPSIZE" != "" ]; then |
---|
106 | #echo "run with heapsize $HADOOP_HEAPSIZE" |
---|
107 | JAVA_HEAP_MAX="-Xmx""$HADOOP_HEAPSIZE""m" |
---|
108 | #echo $JAVA_HEAP_MAX |
---|
109 | fi |
---|
110 | |
---|
111 | # CLASSPATH initially contains $HADOOP_CONF_DIR |
---|
112 | CLASSPATH="${HADOOP_CONF_DIR}" |
---|
113 | CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar |
---|
114 | |
---|
115 | # for developers, add Hadoop classes to CLASSPATH |
---|
116 | if [ -d "$HADOOP_HOME/build/classes" ]; then |
---|
117 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/classes |
---|
118 | fi |
---|
119 | if [ -d "$HADOOP_HOME/build/webapps" ]; then |
---|
120 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build |
---|
121 | fi |
---|
122 | if [ -d "$HADOOP_HOME/build/test/classes" ]; then |
---|
123 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/test/classes |
---|
124 | fi |
---|
125 | if [ -d "$HADOOP_HOME/build/tools" ]; then |
---|
126 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/tools |
---|
127 | fi |
---|
128 | |
---|
129 | # so that filenames w/ spaces are handled correctly in loops below |
---|
130 | IFS= |
---|
131 | |
---|
132 | # for releases, add core hadoop jar & webapps to CLASSPATH |
---|
133 | if [ -d "$HADOOP_HOME/webapps" ]; then |
---|
134 | CLASSPATH=${CLASSPATH}:$HADOOP_HOME |
---|
135 | fi |
---|
136 | for f in $HADOOP_HOME/hadoop-*-core.jar; do |
---|
137 | CLASSPATH=${CLASSPATH}:$f; |
---|
138 | done |
---|
139 | |
---|
140 | # add libs to CLASSPATH |
---|
141 | for f in $HADOOP_HOME/lib/*.jar; do |
---|
142 | CLASSPATH=${CLASSPATH}:$f; |
---|
143 | done |
---|
144 | |
---|
145 | for f in $HADOOP_HOME/lib/jetty-ext/*.jar; do |
---|
146 | CLASSPATH=${CLASSPATH}:$f; |
---|
147 | done |
---|
148 | |
---|
149 | for f in $HADOOP_HOME/hadoop-*-tools.jar; do |
---|
150 | TOOL_PATH=${TOOL_PATH}:$f; |
---|
151 | done |
---|
152 | for f in $HADOOP_HOME/build/hadoop-*-tools.jar; do |
---|
153 | TOOL_PATH=${TOOL_PATH}:$f; |
---|
154 | done |
---|
155 | |
---|
156 | # add user-specified CLASSPATH last |
---|
157 | if [ "$HADOOP_CLASSPATH" != "" ]; then |
---|
158 | CLASSPATH=${CLASSPATH}:${HADOOP_CLASSPATH} |
---|
159 | fi |
---|
160 | |
---|
161 | # default log directory & file |
---|
162 | if [ "$HADOOP_LOG_DIR" = "" ]; then |
---|
163 | HADOOP_LOG_DIR="$HADOOP_HOME/logs" |
---|
164 | fi |
---|
165 | if [ "$HADOOP_LOGFILE" = "" ]; then |
---|
166 | HADOOP_LOGFILE='hadoop.log' |
---|
167 | fi |
---|
168 | |
---|
169 | # restore ordinary behaviour |
---|
170 | unset IFS |
---|
171 | |
---|
172 | # figure out which class to run |
---|
173 | if [ "$COMMAND" = "namenode" ] ; then |
---|
174 | CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode' |
---|
175 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS" |
---|
176 | elif [ "$COMMAND" = "secondarynamenode" ] ; then |
---|
177 | CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode' |
---|
178 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS" |
---|
179 | elif [ "$COMMAND" = "datanode" ] ; then |
---|
180 | CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode' |
---|
181 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_DATANODE_OPTS" |
---|
182 | elif [ "$COMMAND" = "fs" ] ; then |
---|
183 | CLASS=org.apache.hadoop.fs.FsShell |
---|
184 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
185 | elif [ "$COMMAND" = "dfs" ] ; then |
---|
186 | CLASS=org.apache.hadoop.fs.FsShell |
---|
187 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
188 | elif [ "$COMMAND" = "dfsadmin" ] ; then |
---|
189 | CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin |
---|
190 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
191 | elif [ "$COMMAND" = "fsck" ] ; then |
---|
192 | CLASS=org.apache.hadoop.hdfs.tools.DFSck |
---|
193 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
194 | elif [ "$COMMAND" = "balancer" ] ; then |
---|
195 | CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer |
---|
196 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS" |
---|
197 | elif [ "$COMMAND" = "jobtracker" ] ; then |
---|
198 | CLASS=org.apache.hadoop.mapred.JobTracker |
---|
199 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOBTRACKER_OPTS" |
---|
200 | elif [ "$COMMAND" = "tasktracker" ] ; then |
---|
201 | CLASS=org.apache.hadoop.mapred.TaskTracker |
---|
202 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_TASKTRACKER_OPTS" |
---|
203 | elif [ "$COMMAND" = "job" ] ; then |
---|
204 | CLASS=org.apache.hadoop.mapred.JobClient |
---|
205 | elif [ "$COMMAND" = "queue" ] ; then |
---|
206 | CLASS=org.apache.hadoop.mapred.JobQueueClient |
---|
207 | elif [ "$COMMAND" = "pipes" ] ; then |
---|
208 | CLASS=org.apache.hadoop.mapred.pipes.Submitter |
---|
209 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
210 | elif [ "$COMMAND" = "version" ] ; then |
---|
211 | CLASS=org.apache.hadoop.util.VersionInfo |
---|
212 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
213 | elif [ "$COMMAND" = "jar" ] ; then |
---|
214 | CLASS=org.apache.hadoop.mapred.JobShell |
---|
215 | elif [ "$COMMAND" = "distcp" ] ; then |
---|
216 | CLASS=org.apache.hadoop.tools.DistCp |
---|
217 | CLASSPATH=${CLASSPATH}:${TOOL_PATH} |
---|
218 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
219 | elif [ "$COMMAND" = "daemonlog" ] ; then |
---|
220 | CLASS=org.apache.hadoop.log.LogLevel |
---|
221 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
222 | elif [ "$COMMAND" = "archive" ] ; then |
---|
223 | CLASS=org.apache.hadoop.tools.HadoopArchives |
---|
224 | CLASSPATH=${CLASSPATH}:${TOOL_PATH} |
---|
225 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
226 | elif [ "$COMMAND" = "sampler" ] ; then |
---|
227 | CLASS=org.apache.hadoop.mapred.lib.InputSampler |
---|
228 | HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" |
---|
229 | else |
---|
230 | CLASS=$COMMAND |
---|
231 | fi |
---|
232 | |
---|
233 | # cygwin path translation |
---|
234 | if $cygwin; then |
---|
235 | CLASSPATH=`cygpath -p -w "$CLASSPATH"` |
---|
236 | HADOOP_HOME=`cygpath -d "$HADOOP_HOME"` |
---|
237 | HADOOP_LOG_DIR=`cygpath -d "$HADOOP_LOG_DIR"` |
---|
238 | TOOL_PATH=`cygpath -p -w "$TOOL_PATH"` |
---|
239 | fi |
---|
240 | # setup 'java.library.path' for native-hadoop code if necessary |
---|
241 | JAVA_LIBRARY_PATH='' |
---|
242 | if [ -d "${HADOOP_HOME}/build/native" -o -d "${HADOOP_HOME}/lib/native" ]; then |
---|
243 | JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e 's/ /_/g' | sed -e "s/ /_/g"` |
---|
244 | |
---|
245 | if [ -d "$HADOOP_HOME/build/native" ]; then |
---|
246 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/build/native/${JAVA_PLATFORM}/lib |
---|
247 | fi |
---|
248 | |
---|
249 | if [ -d "${HADOOP_HOME}/lib/native" ]; then |
---|
250 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
251 | JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HADOOP_HOME}/lib/native/${JAVA_PLATFORM} |
---|
252 | else |
---|
253 | JAVA_LIBRARY_PATH=${HADOOP_HOME}/lib/native/${JAVA_PLATFORM} |
---|
254 | fi |
---|
255 | fi |
---|
256 | fi |
---|
257 | |
---|
258 | # cygwin path translation |
---|
259 | if $cygwin; then |
---|
260 | JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"` |
---|
261 | fi |
---|
262 | |
---|
263 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR" |
---|
264 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE" |
---|
265 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_HOME" |
---|
266 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING" |
---|
267 | HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}" |
---|
268 | if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then |
---|
269 | HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" |
---|
270 | fi |
---|
271 | |
---|
272 | # run it |
---|
273 | exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@" |
---|