yarn 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 | CLASSNAME]"
  57. echo " CLASSNAME run the class named CLASSNAME"
  58. echo " or"
  59. echo " where COMMAND is one of:"
  60. echo " resourcemanager run the ResourceManager"
  61. echo " Use -format-state-store for deleting the RMStateStore."
  62. echo " Use -remove-application-from-state-store <appId> for "
  63. echo " removing application from RMStateStore."
  64. echo " nodemanager run a nodemanager on each slave"
  65. echo " timelineserver run the timeline server"
  66. echo " rmadmin admin tools"
  67. echo " sharedcachemanager run the SharedCacheManager daemon"
  68. echo " scmadmin SharedCacheManager admin tools"
  69. echo " version print the version"
  70. echo " jar <jar> run a jar file"
  71. echo " application prints application(s)"
  72. echo " report/kill application"
  73. echo " applicationattempt prints applicationattempt(s)"
  74. echo " report"
  75. echo " container prints container(s) report"
  76. echo " node prints node report(s)"
  77. echo " queue prints queue information"
  78. echo " logs dump container logs"
  79. echo " classpath prints the class path needed to"
  80. echo " get the Hadoop jar and the"
  81. echo " required libraries"
  82. echo " cluster prints cluster information"
  83. echo " daemonlog get/set the log level for each"
  84. echo " daemon"
  85. echo " top run cluster usage tool"
  86. echo ""
  87. echo "Most commands print help when invoked w/o parameters."
  88. }
  89. # if no args specified, show usage
  90. if [ $# = 0 ]; then
  91. print_usage
  92. exit 1
  93. fi
  94. # get arguments
  95. COMMAND=$1
  96. shift
  97. case $COMMAND in
  98. # usage flags
  99. --help|-help|-h)
  100. print_usage
  101. exit
  102. ;;
  103. esac
  104. if [ -f "${YARN_CONF_DIR}/yarn-env.sh" ]; then
  105. . "${YARN_CONF_DIR}/yarn-env.sh"
  106. fi
  107. # some Java parameters
  108. if [ "$JAVA_HOME" != "" ]; then
  109. #echo "run java in $JAVA_HOME"
  110. JAVA_HOME=$JAVA_HOME
  111. fi
  112. if [ "$JAVA_HOME" = "" ]; then
  113. echo "Error: JAVA_HOME is not set."
  114. exit 1
  115. fi
  116. JAVA=$JAVA_HOME/bin/java
  117. JAVA_HEAP_MAX=-Xmx1000m
  118. # check envvars which might override default args
  119. if [ "$YARN_HEAPSIZE" != "" ]; then
  120. #echo "run with heapsize $YARN_HEAPSIZE"
  121. JAVA_HEAP_MAX="-Xmx""$YARN_HEAPSIZE""m"
  122. #echo $JAVA_HEAP_MAX
  123. fi
  124. # CLASSPATH initially contains $HADOOP_CONF_DIR & $YARN_CONF_DIR
  125. if [ ! -d "$HADOOP_CONF_DIR" ]; then
  126. echo No HADOOP_CONF_DIR set.
  127. echo Please specify it either in yarn-env.sh or in the environment.
  128. exit 1
  129. fi
  130. CLASSPATH="${HADOOP_CONF_DIR}:${YARN_CONF_DIR}:${CLASSPATH}"
  131. # for developers, add Hadoop classes to CLASSPATH
  132. if [ -d "$HADOOP_YARN_HOME/yarn-api/target/classes" ]; then
  133. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-api/target/classes
  134. fi
  135. if [ -d "$HADOOP_YARN_HOME/yarn-common/target/classes" ]; then
  136. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-common/target/classes
  137. fi
  138. if [ -d "$HADOOP_YARN_HOME/yarn-mapreduce/target/classes" ]; then
  139. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-mapreduce/target/classes
  140. fi
  141. if [ -d "$HADOOP_YARN_HOME/yarn-master-worker/target/classes" ]; then
  142. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-master-worker/target/classes
  143. fi
  144. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes" ]; then
  145. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-nodemanager/target/classes
  146. fi
  147. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes" ]; then
  148. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-common/target/classes
  149. fi
  150. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes" ]; then
  151. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-resourcemanager/target/classes
  152. fi
  153. if [ -d "$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes" ]; then
  154. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/yarn-server/yarn-server-applicationhistoryservice/target/classes
  155. fi
  156. if [ -d "$HADOOP_YARN_HOME/build/test/classes" ]; then
  157. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/target/test/classes
  158. fi
  159. if [ -d "$HADOOP_YARN_HOME/build/tools" ]; then
  160. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/build/tools
  161. fi
  162. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_DIR}/*
  163. CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/${YARN_LIB_JARS_DIR}/*
  164. # Add user defined YARN_USER_CLASSPATH to the class path (if defined)
  165. if [ -n "$YARN_USER_CLASSPATH" ]; then
  166. if [ -n "$YARN_USER_CLASSPATH_FIRST" ]; then
  167. # User requested to add the custom entries at the beginning
  168. CLASSPATH=${YARN_USER_CLASSPATH}:${CLASSPATH}
  169. else
  170. # By default we will just append the extra entries at the end
  171. CLASSPATH=${CLASSPATH}:${YARN_USER_CLASSPATH}
  172. fi
  173. fi
  174. # so that filenames w/ spaces are handled correctly in loops below
  175. IFS=
  176. # default log directory & file
  177. if [ "$YARN_LOG_DIR" = "" ]; then
  178. YARN_LOG_DIR="$HADOOP_YARN_HOME/logs"
  179. fi
  180. if [ "$YARN_LOGFILE" = "" ]; then
  181. YARN_LOGFILE='yarn.log'
  182. fi
  183. # restore ordinary behaviour
  184. unset IFS
  185. # figure out which class to run
  186. if [ "$COMMAND" = "classpath" ] ; then
  187. if [ "$#" -gt 0 ]; then
  188. CLASS=org.apache.hadoop.util.Classpath
  189. else
  190. if [ "$cygwin" = true ]; then
  191. CLASSPATH=$(cygpath -p -w "$CLASSPATH" 2>/dev/null)
  192. fi
  193. echo $CLASSPATH
  194. exit 0
  195. fi
  196. elif [ "$COMMAND" = "rmadmin" ] ; then
  197. CLASS='org.apache.hadoop.yarn.client.cli.RMAdminCLI'
  198. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  199. elif [ "$COMMAND" = "scmadmin" ] ; then
  200. CLASS='org.apache.hadoop.yarn.client.SCMAdmin'
  201. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  202. elif [ "$COMMAND" = "application" ] ||
  203. [ "$COMMAND" = "applicationattempt" ] ||
  204. [ "$COMMAND" = "container" ]; then
  205. CLASS=org.apache.hadoop.yarn.client.cli.ApplicationCLI
  206. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  207. set -- $COMMAND $@
  208. elif [ "$COMMAND" = "node" ] ; then
  209. CLASS=org.apache.hadoop.yarn.client.cli.NodeCLI
  210. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  211. elif [ "$COMMAND" = "queue" ] ; then
  212. CLASS=org.apache.hadoop.yarn.client.cli.QueueCLI
  213. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  214. elif [ "$COMMAND" = "resourcemanager" ] ; then
  215. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/rm-config/log4j.properties
  216. CLASS='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
  217. YARN_OPTS="$YARN_OPTS $YARN_RESOURCEMANAGER_OPTS"
  218. if [ "$YARN_RESOURCEMANAGER_HEAPSIZE" != "" ]; then
  219. JAVA_HEAP_MAX="-Xmx""$YARN_RESOURCEMANAGER_HEAPSIZE""m"
  220. fi
  221. elif [ "$COMMAND" = "historyserver" ] ; then
  222. echo "DEPRECATED: Use of this command to start the timeline server is deprecated." 1>&2
  223. echo "Instead use the timelineserver command for it." 1>&2
  224. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/ahs-config/log4j.properties
  225. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  226. YARN_OPTS="$YARN_OPTS $YARN_HISTORYSERVER_OPTS"
  227. if [ "$YARN_HISTORYSERVER_HEAPSIZE" != "" ]; then
  228. JAVA_HEAP_MAX="-Xmx""$YARN_HISTORYSERVER_HEAPSIZE""m"
  229. fi
  230. elif [ "$COMMAND" = "timelineserver" ] ; then
  231. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/timelineserver-config/log4j.properties
  232. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  233. YARN_OPTS="$YARN_OPTS $YARN_TIMELINESERVER_OPTS"
  234. if [ "$YARN_TIMELINESERVER_HEAPSIZE" != "" ]; then
  235. JAVA_HEAP_MAX="-Xmx""$YARN_TIMELINESERVER_HEAPSIZE""m"
  236. fi
  237. elif [ "$COMMAND" = "sharedcachemanager" ] ; then
  238. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/scm-config/log4j.properties
  239. CLASS='org.apache.hadoop.yarn.server.sharedcachemanager.SharedCacheManager'
  240. YARN_OPTS="$YARN_OPTS $YARN_SHAREDCACHEMANAGER_OPTS"
  241. if [ "$YARN_SHAREDCACHEMANAGER_HEAPSIZE" != "" ]; then
  242. JAVA_HEAP_MAX="-Xmx""$YARN_SHAREDCACHEMANAGER_HEAPSIZE""m"
  243. fi
  244. elif [ "$COMMAND" = "nodemanager" ] ; then
  245. CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/nm-config/log4j.properties
  246. CLASS='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
  247. YARN_OPTS="$YARN_OPTS -server $YARN_NODEMANAGER_OPTS"
  248. if [ "$YARN_NODEMANAGER_HEAPSIZE" != "" ]; then
  249. JAVA_HEAP_MAX="-Xmx""$YARN_NODEMANAGER_HEAPSIZE""m"
  250. fi
  251. elif [ "$COMMAND" = "proxyserver" ] ; then
  252. CLASS='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
  253. YARN_OPTS="$YARN_OPTS $YARN_PROXYSERVER_OPTS"
  254. if [ "$YARN_PROXYSERVER_HEAPSIZE" != "" ]; then
  255. JAVA_HEAP_MAX="-Xmx""$YARN_PROXYSERVER_HEAPSIZE""m"
  256. fi
  257. elif [ "$COMMAND" = "version" ] ; then
  258. CLASS=org.apache.hadoop.util.VersionInfo
  259. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  260. elif [ "$COMMAND" = "jar" ] ; then
  261. CLASS=org.apache.hadoop.util.RunJar
  262. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  263. elif [ "$COMMAND" = "logs" ] ; then
  264. CLASS=org.apache.hadoop.yarn.client.cli.LogsCLI
  265. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  266. elif [ "$COMMAND" = "daemonlog" ] ; then
  267. CLASS=org.apache.hadoop.log.LogLevel
  268. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  269. elif [ "$COMMAND" = "cluster" ] ; then
  270. CLASS=org.apache.hadoop.yarn.client.cli.ClusterCLI
  271. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  272. elif [ "$COMMAND" = "top" ]; then
  273. CLASS=org.apache.hadoop.yarn.client.cli.TopCLI
  274. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  275. doNotSetCols=0
  276. doNotSetRows=0
  277. for i in "$@"; do
  278. if [[ $i == "-cols" ]]; then
  279. doNotSetCols=1
  280. fi
  281. if [[ $i == "-rows" ]]; then
  282. doNotSetRows=1
  283. fi
  284. done
  285. if [ $doNotSetCols == 0 ] && [ -n "${TERM}" ]; then
  286. cols=$(tput cols)
  287. if [ -n "$cols" ]; then
  288. args=( $@ )
  289. args=("${args[@]}" "-cols" "$cols")
  290. set -- "${args[@]}"
  291. fi
  292. fi
  293. if [ $doNotSetRows == 0 ] && [ -n "${TERM}" ]; then
  294. rows=$(tput lines)
  295. if [ -n "$rows" ]; then
  296. args=( $@ )
  297. args=("${args[@]}" "-rows" "$rows")
  298. set -- "${args[@]}"
  299. fi
  300. fi
  301. else
  302. CLASS=$COMMAND
  303. fi
  304. # cygwin path translation
  305. if [ "$cygwin" = true ]; then
  306. CLASSPATH=$(cygpath -p -w "$CLASSPATH" 2>/dev/null)
  307. HADOOP_LOG_DIR=$(cygpath -w "$HADOOP_LOG_DIR" 2>/dev/null)
  308. HADOOP_PREFIX=$(cygpath -w "$HADOOP_PREFIX" 2>/dev/null)
  309. HADOOP_CONF_DIR=$(cygpath -w "$HADOOP_CONF_DIR" 2>/dev/null)
  310. HADOOP_COMMON_HOME=$(cygpath -w "$HADOOP_COMMON_HOME" 2>/dev/null)
  311. HADOOP_HDFS_HOME=$(cygpath -w "$HADOOP_HDFS_HOME" 2>/dev/null)
  312. HADOOP_YARN_HOME=$(cygpath -w "$HADOOP_YARN_HOME" 2>/dev/null)
  313. HADOOP_MAPRED_HOME=$(cygpath -w "$HADOOP_MAPRED_HOME" 2>/dev/null)
  314. YARN_LOG_DIR=$(cygpath -w "$YARN_LOG_DIR" 2>/dev/null)
  315. fi
  316. YARN_OPTS="$YARN_OPTS -Dhadoop.log.dir=$YARN_LOG_DIR"
  317. YARN_OPTS="$YARN_OPTS -Dyarn.log.dir=$YARN_LOG_DIR"
  318. YARN_OPTS="$YARN_OPTS -Dhadoop.log.file=$YARN_LOGFILE"
  319. YARN_OPTS="$YARN_OPTS -Dyarn.log.file=$YARN_LOGFILE"
  320. YARN_OPTS="$YARN_OPTS -Dyarn.home.dir=$HADOOP_YARN_HOME"
  321. if [ "$cygwin" = true ]; then
  322. HADOOP_HOME=$(cygpath -w "$HADOOP_PREFIX" 2>/dev/null)
  323. YARN_OPTS="$YARN_OPTS -Dhadoop.home.dir=$HADOOP_HOME"
  324. export HADOOP_HOME
  325. else
  326. YARN_OPTS="$YARN_OPTS -Dhadoop.home.dir=$HADOOP_PREFIX"
  327. fi
  328. YARN_OPTS="$YARN_OPTS -Dhadoop.root.logger=${YARN_ROOT_LOGGER:-${HADOOP_LOGLEVEL},console}"
  329. YARN_OPTS="$YARN_OPTS -Dyarn.root.logger=${YARN_ROOT_LOGGER:-${HADOOP_LOGLEVEL},console}"
  330. if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
  331. if [ "$cygwin" = true ]; then
  332. JAVA_LIBRARY_PATH=$(cygpath -w "$JAVA_LIBRARY_PATH" 2>/dev/null)
  333. fi
  334. YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
  335. fi
  336. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $YARN_OPTS -classpath "$CLASSPATH" $CLASS "$@"