stop-dfs.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. bin=`dirname "${BASH_SOURCE-$0}"`
  17. bin=`cd "$bin"; pwd`
  18. . "$bin"/hdfs-config.sh
  19. #---------------------------------------------------------
  20. # namenodes
  21. NAMENODES=$($HADOOP_HOME/bin/hdfs getconf -namenodes)
  22. echo "Stopping namenodes on [$NAMENODES]"
  23. "$HADOOP_COMMON_HOME/bin/hadoop-daemons.sh" \
  24. --config "$HADOOP_CONF_DIR" \
  25. --hostnames "$NAMENODES" \
  26. --script "$bin/hdfs" stop namenode
  27. #---------------------------------------------------------
  28. # datanodes (using default slaves file)
  29. if [ -n "$HADOOP_SECURE_DN_USER" ]; then
  30. echo \
  31. "Attempting to stop secure cluster, skipping datanodes. " \
  32. "Run stop-secure-dns.sh as root to complete shutdown."
  33. else
  34. "$HADOOP_COMMON_HOME/bin/hadoop-daemons.sh" \
  35. --config "$HADOOP_CONF_DIR" \
  36. --script "$bin/hdfs" stop datanode
  37. fi
  38. #---------------------------------------------------------
  39. # secondary namenodes (if any)
  40. # if there are no secondary namenodes configured it returns
  41. # 0.0.0.0 or empty string
  42. SECONDARY_NAMENODES=$($HADOOP_HOME/bin/hdfs getconf -secondarynamenodes 2>&-)
  43. SECONDARY_NAMENODES=${SECONDARY_NAMENODES:-'0.0.0.0'}
  44. if [ "$SECONDARY_NAMENODES" = '0.0.0.0' ] ; then
  45. echo \
  46. "Secondary namenodes are not configured. " \
  47. "Cannot stop secondary namenodes."
  48. else
  49. echo "Stopping secondary namenodes [$SECONDARY_NAMENODES]"
  50. "$HADOOP_COMMON_HOME/bin/hadoop-daemons.sh" \
  51. --config "$HADOOP_CONF_DIR" \
  52. --hostnames "$SECONDARY_NAMENODES" \
  53. --script "$bin/hdfs" stop secondarynamenode
  54. fi
  55. # eof