yarn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  54. . $HADOOP_LIBEXEC_DIR/yarn-config.sh
  55. function print_usage(){
  56. echo "Usage: yarn [--config confdir] COMMAND"
  57. echo "where COMMAND is one of:"
  58. echo " resourcemanager -format-state-store deletes the RMStateStore"
  59. echo " resourcemanager run the ResourceManager"
  60. echo " nodemanager run a nodemanager on each slave"
  61. echo " timelineserver run the timeline server"
  62. echo " rmadmin admin tools"
  63. echo " version print the version"
  64. echo " jar <jar> run a jar file"
  65. echo " application prints application(s)"
  66. echo " report/kill application"
  67. echo " applicationattempt prints applicationattempt(s)"
  68. echo " report"
  69. echo " container prints container(s) report"
  70. echo " node prints node report(s)"
  71. echo " queue prints queue information"
  72. echo " logs dump container logs"
  73. echo " classpath prints the class path needed to"
  74. echo " get the Hadoop jar and the"
  75. echo " required libraries"
  76. echo " daemonlog get/set the log level for each"
  77. echo " daemon"
  78. echo " or"
  79. echo " CLASSNAME run the class named CLASSNAME"
  80. echo "Most commands print help when invoked w/o parameters."
  81. }
  82. # if no args specified, show usage
  83. if [ $# = 0 ]; then
  84. print_usage
  85. exit 1
  86. fi
  87. # get arguments
  88. COMMAND=$1
  89. shift
  90. case $COMMAND in
  91. # usage flags
  92. --help|-help|-h)
  93. print_usage
  94. exit
  95. ;;
  96. esac
  97. if [ -f "${YARN_CONF_DIR}/yarn-env.sh" ]; then
  98. . "${YARN_CONF_DIR}/yarn-env.sh"
  99. fi
  100. # some Java parameters
  101. if [ "$JAVA_HOME" != "" ]; then
  102. #echo "run java in $JAVA_HOME"
  103. JAVA_HOME=$JAVA_HOME
  104. fi
  105. if [ "$JAVA_HOME" = "" ]; then
  106. echo "Error: JAVA_HOME is not set."
  107. exit 1
  108. fi
  109. JAVA=$JAVA_HOME/bin/java
  110. JAVA_HEAP_MAX=-Xmx1000m
  111. # check envvars which might override default args
  112. if [ "$YARN_HEAPSIZE" != "" ]; then
  113. #echo "run with heapsize $YARN_HEAPSIZE"
  114. JAVA_HEAP_MAX="-Xmx""$YARN_HEAPSIZE""m"
  115. #echo $JAVA_HEAP_MAX
  116. fi
  117. # CLASSPATH initially contains $HADOOP_CONF_DIR & $YARN_CONF_DIR
  118. if [ ! -d "$HADOOP_CONF_DIR" ]; then
  119. echo No HADOOP_CONF_DIR set.
  120. echo Please specify it either in yarn-env.sh or in the environment.
  121. exit 1
  122. fi
  123. CLASSPATH="${HADOOP_CONF_DIR}:${YARN_CONF_DIR}:${CLASSPATH}"
  124. # for developers, add Hadoop classes to CLASSPATH
  125. if [ -d "$HADOOP_YARN_HOME/yarn-api/target/classes" ]; then
  126. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-api/target/classes
  127. fi
  128. if [ -d "$HADOOP_YARN_HOME/yarn-common/target/classes" ]; then
  129. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-common/target/classes
  130. fi
  131. if [ -d "$HADOOP_YARN_HOME/yarn-mapreduce/target/classes" ]; then
  132. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-mapreduce/target/classes
  133. fi
  134. if [ -d "$HADOOP_YARN_HOME/yarn-master-worker/target/classes" ]; then
  135. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-master-worker/target/classes
  136. fi
  137. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes" ]; then
  138. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes
  139. fi
  140. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes" ]; then
  141. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes
  142. fi
  143. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes" ]; then
  144. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes
  145. fi
  146. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes" ]; then
  147. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes
  148. fi
  149. if [ -d "$HADOOP_YARN_HOME/build/test/classes" ]; then
  150. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/target/test/classes
  151. fi
  152. if [ -d "$HADOOP_YARN_HOME/build/tools" ]; then
  153. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/build/tools
  154. fi
  155. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_DIR}/*
  156. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_LIB_JARS_DIR}/*
  157. # Add user defined YARN_USER_CLASSPATH to the class path (if defined)
  158. if [ -n "$YARN_USER_CLASSPATH" ]; then
  159. if [ -n "$YARN_USER_CLASSPATH_FIRST" ]; then
  160. # User requested to add the custom entries at the beginning
  161. CLASSPATH=${YARN_USER_CLASSPATH}:${CLASSPATH}
  162. else
  163. # By default we will just append the extra entries at the end
  164. CLASSPATH=${CLASSPATH}:${YARN_USER_CLASSPATH}
  165. fi
  166. fi
  167. # so that filenames w/ spaces are handled correctly in loops below
  168. IFS=
  169. # default log directory & file
  170. if [ "$YARN_LOG_DIR" = "" ]; then
  171. YARN_LOG_DIR="$HADOOP_YARN_HOME/logs"
  172. fi
  173. if [ "$YARN_LOGFILE" = "" ]; then
  174. YARN_LOGFILE='yarn.log'
  175. fi
  176. # restore ordinary behaviour
  177. unset IFS
  178. # figure out which class to run
  179. if [ "$COMMAND" = "classpath" ] ; then
  180. echo $CLASSPATH
  181. exit
  182. elif [ "$COMMAND" = "rmadmin" ] ; then
  183. CLASS='org.apache.hadoop.yarn.client.cli.RMAdminCLI'
  184. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  185. elif [ "$COMMAND" = "application" ] ||
  186. [ "$COMMAND" = "applicationattempt" ] ||
  187. [ "$COMMAND" = "container" ]; then
  188. CLASS=org.apache.hadoop.yarn.client.cli.ApplicationCLI
  189. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  190. set -- $COMMAND $@
  191. elif [ "$COMMAND" = "node" ] ; then
  192. CLASS=org.apache.hadoop.yarn.client.cli.NodeCLI
  193. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  194. elif [ "$COMMAND" = "queue" ] ; then
  195. CLASS=org.apache.hadoop.yarn.client.cli.QueueCLI
  196. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  197. elif [ "$COMMAND" = "resourcemanager" ] ; then
  198. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/rm-config/log4j.properties
  199. CLASS='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
  200. YARN_OPTS="$YARN_OPTS $YARN_RESOURCEMANAGER_OPTS"
  201. if [ "$YARN_RESOURCEMANAGER_HEAPSIZE" != "" ]; then
  202. JAVA_HEAP_MAX="-Xmx""$YARN_RESOURCEMANAGER_HEAPSIZE""m"
  203. fi
  204. elif [ "$COMMAND" = "historyserver" ] ; then
  205. echo "DEPRECATED: Use of this command to start the timeline server is deprecated." 1>&2
  206. echo "Instead use the timelineserver command for it." 1>&2
  207. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/ahs-config/log4j.properties
  208. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  209. YARN_OPTS="$YARN_OPTS $YARN_HISTORYSERVER_OPTS"
  210. if [ "$YARN_HISTORYSERVER_HEAPSIZE" != "" ]; then
  211. JAVA_HEAP_MAX="-Xmx""$YARN_HISTORYSERVER_HEAPSIZE""m"
  212. fi
  213. elif [ "$COMMAND" = "timelineserver" ] ; then
  214. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/timelineserver-config/log4j.properties
  215. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  216. YARN_OPTS="$YARN_OPTS $YARN_TIMELINESERVER_OPTS"
  217. if [ "$YARN_TIMELINESERVER_HEAPSIZE" != "" ]; then
  218. JAVA_HEAP_MAX="-Xmx""$YARN_TIMELINESERVER_HEAPSIZE""m"
  219. fi
  220. elif [ "$COMMAND" = "nodemanager" ] ; then
  221. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/nm-config/log4j.properties
  222. CLASS='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
  223. YARN_OPTS="$YARN_OPTS -server $YARN_NODEMANAGER_OPTS"
  224. if [ "$YARN_NODEMANAGER_HEAPSIZE" != "" ]; then
  225. JAVA_HEAP_MAX="-Xmx""$YARN_NODEMANAGER_HEAPSIZE""m"
  226. fi
  227. elif [ "$COMMAND" = "proxyserver" ] ; then
  228. CLASS='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
  229. YARN_OPTS="$YARN_OPTS $YARN_PROXYSERVER_OPTS"
  230. if [ "$YARN_PROXYSERVER_HEAPSIZE" != "" ]; then
  231. JAVA_HEAP_MAX="-Xmx""$YARN_PROXYSERVER_HEAPSIZE""m"
  232. fi
  233. elif [ "$COMMAND" = "version" ] ; then
  234. CLASS=org.apache.hadoop.util.VersionInfo
  235. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  236. elif [ "$COMMAND" = "jar" ] ; then
  237. CLASS=org.apache.hadoop.util.RunJar
  238. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  239. elif [ "$COMMAND" = "logs" ] ; then
  240. CLASS=org.apache.hadoop.yarn.client.cli.LogsCLI
  241. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  242. elif [ "$COMMAND" = "daemonlog" ] ; then
  243. CLASS=org.apache.hadoop.log.LogLevel
  244. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  245. else
  246. CLASS=$COMMAND
  247. fi
  248. YARN_OPTS="$YARN_OPTS -Dhadoop.log.dir=$YARN_LOG_DIR"
  249. YARN_OPTS="$YARN_OPTS -Dyarn.log.dir=$YARN_LOG_DIR"
  250. YARN_OPTS="$YARN_OPTS -Dhadoop.log.file=$YARN_LOGFILE"
  251. YARN_OPTS="$YARN_OPTS -Dyarn.log.file=$YARN_LOGFILE"
  252. YARN_OPTS="$YARN_OPTS -Dyarn.home.dir=$HADOOP_YARN_HOME"
  253. YARN_OPTS="$YARN_OPTS -Dhadoop.home.dir=$HADOOP_YARN_HOME"
  254. YARN_OPTS="$YARN_OPTS -Dhadoop.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
  255. YARN_OPTS="$YARN_OPTS -Dyarn.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
  256. if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
  257. YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
  258. fi
  259. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $YARN_OPTS -classpath "$CLASSPATH" $CLASS "$@"