refresh-namenodes.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # ------------------------------------------------------------------
  17. # This script refreshes all namenodes, it's a simple wrapper
  18. # for dfsadmin to support multiple namenodes.
  19. # let's locate libexec...
  20. if [[ -n "${HADOOP_PREFIX}" ]]; then
  21. DEFAULT_LIBEXEC_DIR="${HADOOP_PREFIX}/libexec"
  22. else
  23. this="${BASH_SOURCE-$0}"
  24. bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  25. DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  26. fi
  27. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}"
  28. # shellcheck disable=SC2034
  29. HADOOP_NEW_CONFIG=true
  30. if [[ -f "${HADOOP_LIBEXEC_DIR}/hdfs-config.sh" ]]; then
  31. . "${HADOOP_LIBEXEC_DIR}/hdfs-config.sh"
  32. else
  33. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hdfs-config.sh." 2>&1
  34. exit 1
  35. fi
  36. namenodes=$("${HADOOP_HDFS_HOME}/bin/hdfs" getconf -nnRpcAddresses)
  37. if [[ "$?" != '0' ]] ; then
  38. errorFlag='1' ;
  39. else
  40. for namenode in ${namenodes} ; do
  41. echo "Refreshing namenode [${namenode}]"
  42. "${HADOOP_HDFS_HOME}/bin/hdfs" dfsadmin \
  43. -fs hdfs://${namenode} -refreshNodes
  44. if [[ "$?" != '0' ]]; then
  45. errorFlag='1'
  46. fi
  47. done
  48. fi
  49. if [[ "${errorFlag}" = '1' ]] ; then
  50. echo "Error: refresh of namenodes failed, see error messages above."
  51. exit 1
  52. else
  53. echo "Refresh of namenodes done."
  54. fi
  55. # eof