stop-yarn.sh 3.0 KB

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