yarn 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. function hadoop_usage
  17. {
  18. echo "Usage: yarn [--config confdir] [--daemon (start|stop|status)]"
  19. echo " [--loglevel loglevel] COMMAND"
  20. echo "where COMMAND is one of:"
  21. echo " application prints application(s) report/kill application"
  22. echo " applicationattempt prints applicationattempt(s) report"
  23. echo " classpath prints the class path needed to get the"
  24. echo " Hadoop jar and the required libraries"
  25. echo " container prints container(s) report"
  26. echo " daemonlog get/set the log level for each daemon"
  27. echo " jar <jar> run a jar file"
  28. echo " logs dump container logs"
  29. echo " node prints node report(s)"
  30. echo " nodemanager run a nodemanager on each slave"
  31. echo " proxyserver run the web app proxy server"
  32. echo " queue prints queue information"
  33. echo " resourcemanager run the ResourceManager"
  34. echo " resourcemanager -format-state-store deletes the RMStateStore"
  35. echo " rmadmin admin tools"
  36. echo " sharedcachemanager run the SharedCacheManager daemon"
  37. echo " scmadmin SharedCacheManager admin tools"
  38. echo " timelineserver run the timeline server"
  39. echo " version print the version"
  40. echo " or"
  41. echo " CLASSNAME run the class named CLASSNAME"
  42. echo "Most commands print help when invoked w/o parameters."
  43. }
  44. # let's locate libexec...
  45. if [[ -n "${HADOOP_PREFIX}" ]]; then
  46. DEFAULT_LIBEXEC_DIR="${HADOOP_PREFIX}/libexec"
  47. else
  48. this="${BASH_SOURCE-$0}"
  49. bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  50. DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  51. fi
  52. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}"
  53. # shellcheck disable=SC2034
  54. HADOOP_NEW_CONFIG=true
  55. if [[ -f "${HADOOP_LIBEXEC_DIR}/yarn-config.sh" ]]; then
  56. . "${HADOOP_LIBEXEC_DIR}/yarn-config.sh"
  57. else
  58. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/yarn-config.sh." 2>&1
  59. exit 1
  60. fi
  61. # if no args specified, show usage
  62. if [[ $# = 0 ]]; then
  63. hadoop_exit_with_usage 1
  64. fi
  65. # get arguments
  66. COMMAND=$1
  67. shift
  68. case "${COMMAND}" in
  69. application|applicationattempt|container)
  70. CLASS=org.apache.hadoop.yarn.client.cli.ApplicationCLI
  71. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  72. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  73. set -- "${COMMAND}" "$@"
  74. ;;
  75. classpath)
  76. hadoop_finalize
  77. echo "${CLASSPATH}"
  78. exit
  79. ;;
  80. daemonlog)
  81. CLASS=org.apache.hadoop.log.LogLevel
  82. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  83. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  84. ;;
  85. jar)
  86. CLASS=org.apache.hadoop.util.RunJar
  87. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  88. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  89. ;;
  90. historyserver)
  91. supportdaemonization="true"
  92. echo "DEPRECATED: Use of this command to start the timeline server is deprecated." 1>&2
  93. echo "Instead use the timelineserver command for it." 1>&2
  94. echo "Starting the History Server anyway..." 1>&2
  95. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  96. ;;
  97. logs)
  98. CLASS=org.apache.hadoop.yarn.client.cli.LogsCLI
  99. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  100. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  101. ;;
  102. node)
  103. CLASS=org.apache.hadoop.yarn.client.cli.NodeCLI
  104. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  105. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  106. ;;
  107. nodemanager)
  108. supportdaemonization="true"
  109. CLASS='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
  110. hadoop_debug "Append YARN_NODEMANAGER_OPTS onto YARN_OPTS"
  111. YARN_OPTS="${YARN_OPTS} ${YARN_NODEMANAGER_OPTS}"
  112. # Backwards compatibility
  113. if [[ -n "${YARN_NODEMANAGER_HEAPSIZE}" ]]; then
  114. HADOOP_HEAPSIZE_MAX="${YARN_NODEMANAGER_HEAPSIZE}"
  115. fi
  116. ;;
  117. proxyserver)
  118. supportdaemonization="true"
  119. CLASS='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
  120. hadoop_debug "Append YARN_PROXYSERVER_OPTS onto YARN_OPTS"
  121. YARN_OPTS="${YARN_OPTS} ${YARN_PROXYSERVER_OPTS}"
  122. # Backwards compatibility
  123. if [[ -n "${YARN_PROXYSERVER_HEAPSIZE}" ]]; then
  124. HADOOP_HEAPSIZE_MAX="${YARN_PROXYSERVER_HEAPSIZE}"
  125. fi
  126. ;;
  127. queue)
  128. CLASS=org.apache.hadoop.yarn.client.cli.QueueCLI
  129. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  130. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  131. ;;
  132. resourcemanager)
  133. supportdaemonization="true"
  134. CLASS='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
  135. YARN_OPTS="${YARN_OPTS} ${YARN_RESOURCEMANAGER_OPTS}"
  136. hadoop_debug "Append YARN_RESOURCEMANAGER_OPTS onto YARN_OPTS"
  137. # Backwards compatibility
  138. if [[ -n "${YARN_RESOURCEMANAGER_HEAPSIZE}" ]]; then
  139. HADOOP_HEAPSIZE_MAX="${YARN_RESOURCEMANAGER_HEAPSIZE}"
  140. fi
  141. ;;
  142. rmadmin)
  143. CLASS='org.apache.hadoop.yarn.client.cli.RMAdminCLI'
  144. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  145. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  146. ;;
  147. timelineserver)
  148. supportdaemonization="true"
  149. CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  150. hadoop_debug "Append YARN_TIMELINESERVER_OPTS onto YARN_OPTS"
  151. YARN_OPTS="${YARN_OPTS} ${YARN_TIMELINESERVER_OPTS}"
  152. # Backwards compatibility
  153. if [[ -n "${YARN_TIMELINESERVER_HEAPSIZE}" ]]; then
  154. HADOOP_HEAPSIZE_MAX="${YARN_TIMELINESERVER_HEAPSIZE}"
  155. fi
  156. ;;
  157. sharedcachemanager)
  158. supportdaemonization="true"
  159. CLASS='org.apache.hadoop.yarn.server.sharedcachemanager.SharedCacheManager'
  160. YARN_OPTS="$YARN_OPTS $YARN_SHAREDCACHEMANAGER_OPTS"
  161. ;;
  162. scmadmin)
  163. CLASS='org.apache.hadoop.yarn.client.SCMAdmin'
  164. YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
  165. ;;
  166. version)
  167. CLASS=org.apache.hadoop.util.VersionInfo
  168. hadoop_debug "Append YARN_CLIENT_OPTS onto YARN_OPTS"
  169. YARN_OPTS="${YARN_OPTS} ${YARN_CLIENT_OPTS}"
  170. ;;
  171. *)
  172. CLASS="${COMMAND}"
  173. if ! hadoop_validate_classname "${CLASS}"; then
  174. hadoop_exit_with_usage 1
  175. fi
  176. ;;
  177. esac
  178. # set HADOOP_OPTS to YARN_OPTS so that we can use
  179. # finalize, etc, without doing anything funky
  180. hadoop_debug "Resetting HADOOP_OPTS=YARN_OPTS"
  181. # shellcheck disable=SC2034
  182. HADOOP_OPTS="${YARN_OPTS}"
  183. daemon_outfile="${HADOOP_LOG_DIR}/hadoop-${HADOOP_IDENT_STRING}-${COMMAND}-${HOSTNAME}.out"
  184. daemon_pidfile="${HADOOP_PID_DIR}/hadoop-${HADOOP_IDENT_STRING}-${COMMAND}.pid"
  185. if [[ "${HADOOP_DAEMON_MODE}" != "default" ]]; then
  186. # shellcheck disable=SC2034
  187. HADOOP_ROOT_LOGGER="${HADOOP_DAEMON_ROOT_LOGGER}"
  188. YARN_ROOT_LOGGER="${HADOOP_DAEMON_ROOT_LOGGER}"
  189. HADOOP_LOGFILE="hadoop-${HADOOP_IDENT_STRING}-${COMMAND}-${HOSTNAME}.log"
  190. fi
  191. # Add YARN custom options to comamnd line in case someone actaully
  192. # used these.
  193. #
  194. # Note that we are replacing ' ' with '\ ' so that when we exec
  195. # stuff it works
  196. #
  197. hadoop_add_param HADOOP_OPTS yarn.log.dir "-Dyarn.log.dir=${HADOOP_LOG_DIR/ /\ }"
  198. hadoop_add_param HADOOP_OPTS yarn.log.file "-Dyarn.log.file=${HADOOP_LOGFILE/ /\ }"
  199. hadoop_add_param HADOOP_OPTS yarn.home.dir "-Dyarn.home.dir=${HADOOP_YARN_HOME/ /\ }"
  200. hadoop_add_param HADOOP_OPTS yarn.root.logger "-Dyarn.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
  201. hadoop_finalize
  202. if [[ -n "${supportdaemonization}" ]]; then
  203. if [[ -n "${secure_service}" ]]; then
  204. hadoop_secure_daemon_handler "${HADOOP_DAEMON_MODE}" "${COMMAND}" \
  205. "${CLASS}" "${daemon_pidfile}" "${daemon_outfile}" \
  206. "${priv_pidfile}" "${priv_outfile}" "${priv_errfile}" "$@"
  207. else
  208. hadoop_daemon_handler "${HADOOP_DAEMON_MODE}" "${COMMAND}" "${CLASS}" \
  209. "${daemon_pidfile}" "${daemon_outfile}" "$@"
  210. fi
  211. exit $?
  212. else
  213. hadoop_java_exec "${COMMAND}" "${CLASS}" "$@"
  214. fi