yarn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # The Hadoop command script
  17. #
  18. # Environment Variables
  19. #
  20. # JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
  21. #
  22. # YARN_USER_CLASSPATH Additional user CLASSPATH entries.
  23. #
  24. # YARN_USER_CLASSPATH_FIRST If set to non empty value then the user classpath
  25. # specified in YARN_USER_CLASSPATH will be
  26. # appended at the beginning of YARN's final
  27. # classpath instead of at the end.
  28. #
  29. # YARN_HEAPSIZE The maximum amount of heap to use, in MB.
  30. # Default is 1000.
  31. #
  32. # YARN_{COMMAND}_HEAPSIZE overrides YARN_HEAPSIZE for a given command
  33. # eg YARN_NODEMANAGER_HEAPSIZE sets the heap
  34. # size for the NodeManager. If you set the
  35. # heap size in YARN_{COMMAND}_OPTS or YARN_OPTS
  36. # they take precedence.
  37. #
  38. # YARN_OPTS Extra Java runtime options.
  39. #
  40. # YARN_CLIENT_OPTS when the respective command is run.
  41. # YARN_{COMMAND}_OPTS etc YARN_NODEMANAGER_OPTS applies to NodeManager
  42. # for e.g. YARN_CLIENT_OPTS applies to
  43. # more than one command (fs, dfs, fsck,
  44. # dfsadmin etc)
  45. #
  46. # YARN_CONF_DIR Alternate conf dir. Default is ${HADOOP_YARN_HOME}/conf.
  47. #
  48. # YARN_ROOT_LOGGER The root appender. Default is INFO,console
  49. #
  50. bin=`dirname "${BASH_SOURCE-$0}"`
  51. bin=`cd "$bin"; pwd`
  52. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  53. if [ -n "$HADOOP_HOME" ]; then
  54. DEFAULT_LIBEXEC_DIR="$HADOOP_HOME"/libexec
  55. fi
  56. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  57. . $HADOOP_LIBEXEC_DIR/yarn-config.sh
  58. function print_usage(){
  59. echo "Usage: yarn [--config confdir] COMMAND"
  60. echo "where COMMAND is one of:"
  61. echo " resourcemanager -format-state-store deletes the RMStateStore"
  62. echo " resourcemanager run the ResourceManager"
  63. echo " nodemanager run a nodemanager on each slave"
  64. echo " timelineserver run the timeline server"
  65. echo " rmadmin admin tools"
  66. echo " version print the version"
  67. echo " jar <jar> run a jar file"
  68. echo " application prints application(s)"
  69. echo " report/kill application"
  70. echo " applicationattempt prints applicationattempt(s)"
  71. echo " report"
  72. echo " container prints container(s) report"
  73. echo " node prints node report(s)"
  74. echo " cluster print cluster information"
  75. echo " queue prints queue information"
  76. echo " logs dump container logs"
  77. echo " classpath prints the class path needed to"
  78. echo " get the Hadoop jar and the"
  79. echo " required libraries"
  80. echo " daemonlog get/set the log level for each"
  81. echo " daemon"
  82. echo " or"
  83. echo " CLASSNAME run the class named CLASSNAME"
  84. echo "Most commands print help when invoked w/o parameters."
  85. }
  86. # if no args specified, show usage
  87. if [ $# = 0 ]; then
  88. print_usage
  89. exit 1
  90. fi
  91. # get arguments
  92. COMMAND=$1
  93. shift
  94. case $COMMAND in
  95. # usage flags
  96. --help|-help|-h)
  97. print_usage
  98. exit
  99. ;;
  100. esac
  101. if [ -f "${YARN_CONF_DIR}/yarn-env.sh" ]; then
  102. . "${YARN_CONF_DIR}/yarn-env.sh"
  103. fi
  104. # some Java parameters
  105. if [ "$JAVA_HOME" != "" ]; then
  106. #echo "run java in $JAVA_HOME"
  107. JAVA_HOME=$JAVA_HOME
  108. fi
  109. if [ "$JAVA_HOME" = "" ]; then
  110. echo "Error: JAVA_HOME is not set."
  111. exit 1
  112. fi
  113. JAVA=$JAVA_HOME/bin/java
  114. JAVA_HEAP_MAX=-Xmx1000m
  115. # check envvars which might override default args
  116. if [ "$YARN_HEAPSIZE" != "" ]; then
  117. #echo "run with heapsize $YARN_HEAPSIZE"
  118. JAVA_HEAP_MAX="-Xmx""$YARN_HEAPSIZE""m"
  119. #echo $JAVA_HEAP_MAX
  120. fi
  121. # CLASSPATH initially contains $HADOOP_CONF_DIR & $YARN_CONF_DIR
  122. if [ ! -d "$HADOOP_CONF_DIR" ]; then
  123. echo No HADOOP_CONF_DIR set.
  124. echo Please specify it either in yarn-env.sh or in the environment.
  125. exit 1
  126. fi
  127. CLASSPATH="${HADOOP_CONF_DIR}:${YARN_CONF_DIR}:${CLASSPATH}"
  128. # for developers, add Hadoop classes to CLASSPATH
  129. if [ -d "$HADOOP_YARN_HOME/yarn-api/target/classes" ]; then
  130. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-api/target/classes
  131. fi
  132. if [ -d "$HADOOP_YARN_HOME/yarn-common/target/classes" ]; then
  133. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-common/target/classes
  134. fi
  135. if [ -d "$HADOOP_YARN_HOME/yarn-mapreduce/target/classes" ]; then
  136. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-mapreduce/target/classes
  137. fi
  138. if [ -d "$HADOOP_YARN_HOME/yarn-master-worker/target/classes" ]; then
  139. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-master-worker/target/classes
  140. fi
  141. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes" ]; then
  142. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes
  143. fi
  144. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes" ]; then
  145. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes
  146. fi
  147. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes" ]; then
  148. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes
  149. fi
  150. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes" ]; then
  151. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes
  152. fi
  153. if [ -d "$HADOOP_YARN_HOME/build/test/classes" ]; then
  154. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/target/test/classes
  155. fi
  156. if [ -d "$HADOOP_YARN_HOME/build/tools" ]; then
  157. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/build/tools
  158. fi
  159. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_DIR}/*
  160. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_LIB_JARS_DIR}/*
  161. # Add user defined YARN_USER_CLASSPATH to the class path (if defined)
  162. if [ -n "$YARN_USER_CLASSPATH" ]; then
  163. if [ -n "$YARN_USER_CLASSPATH_FIRST" ]; then
  164. # User requested to add the custom entries at the beginning
  165. CLASSPATH=${YARN_USER_CLASSPATH}:${CLASSPATH}
  166. else
  167. # By default we will just append the extra entries at the end
  168. CLASSPATH=${CLASSPATH}:${YARN_USER_CLASSPATH}
  169. fi
  170. fi
  171. # so that filenames w/ spaces are handled correctly in loops below
  172. IFS=
  173. # default log directory & file
  174. if [ "$YARN_LOG_DIR" = "" ]; then
  175. YARN_LOG_DIR="$HADOOP_YARN_HOME/logs"
  176. fi
  177. if [ "$YARN_LOGFILE" = "" ]; then
  178. YARN_LOGFILE='yarn.log'
  179. fi
  180. # restore ordinary behaviour
  181. unset IFS
  182. # figure out which class to run
  183. if [ "$COMMAND" = "classpath" ] ; then
  184. echo $CLASSPATH
  185. exit
  186. elif [ "$COMMAND" = "rmadmin" ] ; then
  187. CLASS='org.apache.hadoop.yarn.client.cli.RMAdminCLI'
  188. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  189. elif [ "$COMMAND" = "application" ] ||
  190. [ "$COMMAND" = "applicationattempt" ] ||
  191. [ "$COMMAND" = "container" ]; then
  192. CLASS=org.apache.hadoop.yarn.client.cli.ApplicationCLI
  193. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  194. set -- $COMMAND $@
  195. elif [ "$COMMAND" = "node" ] ; then
  196. CLASS=org.apache.hadoop.yarn.client.cli.NodeCLI
  197. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  198. elif [ "$COMMAND" = "queue" ] ; then
  199. CLASS=org.apache.hadoop.yarn.client.cli.QueueCLI
  200. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  201. elif [ "$COMMAND" = "resourcemanager" ] ; then
  202. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/rm-config/log4j.properties
  203. CLASS='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
  204. YARN_OPTS="$YARN_OPTS $YARN_RESOURCEMANAGER_OPTS"
  205. if [ "$YARN_RESOURCEMANAGER_HEAPSIZE" != "" ]; then
  206. JAVA_HEAP_MAX="-Xmx""$YARN_RESOURCEMANAGER_HEAPSIZE""m"
  207. fi
  208. elif [ "$COMMAND" = "historyserver" ] ; then
  209. echo "DEPRECATED: Use of this command to start the timeline server is deprecated." 1>&2
  210. echo "Instead use the timelineserver command for it." 1>&2
  211. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/ahs-config/log4j.properties
  212. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  213. YARN_OPTS="$YARN_OPTS $YARN_HISTORYSERVER_OPTS"
  214. if [ "$YARN_HISTORYSERVER_HEAPSIZE" != "" ]; then
  215. JAVA_HEAP_MAX="-Xmx""$YARN_HISTORYSERVER_HEAPSIZE""m"
  216. fi
  217. elif [ "$COMMAND" = "timelineserver" ] ; then
  218. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/timelineserver-config/log4j.properties
  219. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  220. YARN_OPTS="$YARN_OPTS $YARN_TIMELINESERVER_OPTS"
  221. if [ "$YARN_TIMELINESERVER_HEAPSIZE" != "" ]; then
  222. JAVA_HEAP_MAX="-Xmx""$YARN_TIMELINESERVER_HEAPSIZE""m"
  223. fi
  224. elif [ "$COMMAND" = "nodemanager" ] ; then
  225. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/nm-config/log4j.properties
  226. CLASS='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
  227. YARN_OPTS="$YARN_OPTS -server $YARN_NODEMANAGER_OPTS"
  228. if [ "$YARN_NODEMANAGER_HEAPSIZE" != "" ]; then
  229. JAVA_HEAP_MAX="-Xmx""$YARN_NODEMANAGER_HEAPSIZE""m"
  230. fi
  231. elif [ "$COMMAND" = "proxyserver" ] ; then
  232. CLASS='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
  233. YARN_OPTS="$YARN_OPTS $YARN_PROXYSERVER_OPTS"
  234. if [ "$YARN_PROXYSERVER_HEAPSIZE" != "" ]; then
  235. JAVA_HEAP_MAX="-Xmx""$YARN_PROXYSERVER_HEAPSIZE""m"
  236. fi
  237. elif [ "$COMMAND" = "version" ] ; then
  238. CLASS=org.apache.hadoop.util.VersionInfo
  239. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  240. elif [ "$COMMAND" = "jar" ] ; then
  241. CLASS=org.apache.hadoop.util.RunJar
  242. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  243. elif [ "$COMMAND" = "logs" ] ; then
  244. CLASS=org.apache.hadoop.yarn.client.cli.LogsCLI
  245. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  246. elif [ "$COMMAND" = "daemonlog" ] ; then
  247. CLASS=org.apache.hadoop.log.LogLevel
  248. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  249. elif [ "$COMMAND" = "cluster" ] ; then
  250. CLASS=org.apache.hadoop.yarn.client.cli.ClusterCLI
  251. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  252. else
  253. CLASS=$COMMAND
  254. fi
  255. YARN_OPTS="$YARN_OPTS -Dhadoop.log.dir=$YARN_LOG_DIR"
  256. YARN_OPTS="$YARN_OPTS -Dyarn.log.dir=$YARN_LOG_DIR"
  257. YARN_OPTS="$YARN_OPTS -Dhadoop.log.file=$YARN_LOGFILE"
  258. YARN_OPTS="$YARN_OPTS -Dyarn.log.file=$YARN_LOGFILE"
  259. YARN_OPTS="$YARN_OPTS -Dyarn.home.dir=$HADOOP_YARN_HOME"
  260. YARN_OPTS="$YARN_OPTS -Dhadoop.home.dir=$HADOOP_YARN_HOME"
  261. YARN_OPTS="$YARN_OPTS -Dhadoop.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
  262. YARN_OPTS="$YARN_OPTS -Dyarn.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
  263. if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
  264. YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
  265. fi
  266. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $YARN_OPTS -classpath "$CLASSPATH" $CLASS "$@"