distribute-exclude.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #
  18. # The purpose of this script is to distribute the exclude file (see
  19. # "dfs.hosts.exclude" in hdfs-site.xml).
  20. #
  21. # Input of the script is a local exclude file. The exclude file
  22. # will be distributed to all the namenodes. The location on the namenodes
  23. # is determined by the configuration "dfs.hosts.exclude" in hdfs-site.xml
  24. # (this value is read from the local copy of hdfs-site.xml and must be same
  25. # on all the namenodes).
  26. #
  27. # The user running this script needs write permissions on the target
  28. # directory on namenodes.
  29. #
  30. # After this command, run refresh-namenodes.sh so that namenodes start
  31. # using the new exclude file.
  32. bin=`dirname "$0"`
  33. bin=`cd "$bin"; pwd`
  34. if [ -e "$bin/../libexec/hdfs-config.sh" ]; then
  35. . "$bin/../libexec/hdfs-config.sh"
  36. else
  37. . "$bin/hdfs-config.sh"
  38. fi
  39. if [ "$1" = '' ] ; then
  40. "Error: please specify local exclude file as a first argument"
  41. exit 1
  42. else
  43. excludeFilenameLocal=$1
  44. fi
  45. if [ ! -f "$excludeFilenameLocal" ] ; then
  46. echo "Error: exclude file [$excludeFilenameLocal] does not exist."
  47. exit 1
  48. fi
  49. namenodes=$("$HADOOP_PREFIX/bin/hdfs" getconf -namenodes)
  50. excludeFilenameRemote=$("$HADOOP_PREFIX/bin/hdfs" getconf -excludeFile)
  51. if [ "$excludeFilenameRemote" = '' ] ; then
  52. echo \
  53. "Error: hdfs getconf -excludeFile returned empty string, " \
  54. "please setup dfs.hosts.exclude in hdfs-site.xml in local cluster " \
  55. "configuration and on all namenodes"
  56. exit 1
  57. fi
  58. echo "Copying exclude file [$excludeFilenameRemote] to namenodes:"
  59. for namenode in $namenodes ; do
  60. echo " [$namenode]"
  61. scp "$excludeFilenameLocal" "$namenode:$excludeFilenameRemote"
  62. if [ "$?" != '0' ] ; then errorFlag='1' ; fi
  63. done
  64. if [ "$errorFlag" = '1' ] ; then
  65. echo "Error: transfer of exclude file failed, see error messages above."
  66. exit 1
  67. else
  68. echo "Transfer of exclude file to all namenodes succeeded."
  69. fi
  70. # eof