stop-yarn.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. MYNAME="${BASH_SOURCE-$0}"
  17. function hadoop_usage
  18. {
  19. hadoop_generate_usage "${MYNAME}" false
  20. }
  21. bin=$(cd -P -- "$(dirname -- "${MYNAME}")" >/dev/null && pwd -P)
  22. # let's locate libexec...
  23. if [[ -n "${HADOOP_PREFIX}" ]]; then
  24. HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_PREFIX}/libexec"
  25. else
  26. HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  27. fi
  28. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}"
  29. # shellcheck disable=SC2034
  30. HADOOP_NEW_CONFIG=true
  31. if [[ -f "${HADOOP_LIBEXEC_DIR}/yarn-config.sh" ]]; then
  32. . "${HADOOP_LIBEXEC_DIR}/yarn-config.sh"
  33. else
  34. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/yarn-config.sh." 2>&1
  35. exit 1
  36. fi
  37. # stop resourceManager
  38. HARM=$("${HADOOP_HDFS_HOME}/bin/hdfs" getconf -confKey yarn.resourcemanager.ha.enabled 2>&-)
  39. if [[ ${HARM} = "false" ]]; then
  40. echo "Stopping resourcemanager"
  41. "${HADOOP_YARN_HOME}/bin/yarn" \
  42. --config "${HADOOP_CONF_DIR}" \
  43. --daemon stop \
  44. resourcemanager
  45. else
  46. logicals=$("${HADOOP_HDFS_HOME}/bin/hdfs" getconf -confKey yarn.resourcemanager.ha.rm-ids 2>&-)
  47. logicals=${logicals//,/ }
  48. for id in ${logicals}
  49. do
  50. rmhost=$("${HADOOP_HDFS_HOME}/bin/hdfs" getconf -confKey "yarn.resourcemanager.hostname.${id}" 2>&-)
  51. RMHOSTS="${RMHOSTS} ${rmhost}"
  52. done
  53. echo "Stopping resourcemanagers on [${RMHOSTS}]"
  54. "${HADOOP_YARN_HOME}/bin/yarn" \
  55. --config "${HADOOP_CONF_DIR}" \
  56. --daemon stop \
  57. --slaves \
  58. --hostnames "${RMHOSTS}" \
  59. resourcemanager
  60. fi
  61. # stop nodemanager
  62. echo "Stopping nodemanagers"
  63. "${HADOOP_YARN_HOME}/bin/yarn" \
  64. --config "${HADOOP_CONF_DIR}" \
  65. --slaves \
  66. --daemon stop \
  67. nodemanager
  68. # stop proxyserver
  69. PROXYSERVER=$("${HADOOP_HDFS_HOME}/bin/hdfs" getconf -confKey yarn.web-proxy.address 2>&- | cut -f1 -d:)
  70. if [[ -n ${PROXYSERVER} ]]; then
  71. echo "Stopping proxy server [${PROXYSERVER}]"
  72. "${HADOOP_YARN_HOME}/bin/yarn" \
  73. --config "${HADOOP_CONF_DIR}" \
  74. --slaves \
  75. --hostnames "${PROXYSERVER}" \
  76. --daemon stop \
  77. proxyserver
  78. fi