stop-zookeeper-quorum.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. ################################################################################
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ################################################################################
  19. bin=`dirname "$0"`
  20. bin=`cd "$bin"; pwd`
  21. . "$bin"/config.sh
  22. # Stops a ZooKeeper quorum as configured in $FLINK_CONF/zoo.cfg
  23. ZK_CONF="$FLINK_CONF_DIR/zoo.cfg"
  24. if [ ! -f "$ZK_CONF" ]; then
  25. echo "[ERROR] No ZooKeeper configuration file found in '$ZK_CONF'."
  26. exit 1
  27. fi
  28. # Extract server.X from ZooKeeper config and stop instances
  29. while read server ; do
  30. server=$(echo -e "${server}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') # trim
  31. # match server.id=address[:port[:port]]
  32. if [[ $server =~ ^server\.([0-9]+)[[:space:]]*\=[[:space:]]*([^: \#]+) ]]; then
  33. id=${BASH_REMATCH[1]}
  34. server=${BASH_REMATCH[2]}
  35. ssh -n $FLINK_SSH_OPTS $server -- "nohup /bin/bash -l $FLINK_BIN_DIR/zookeeper.sh stop &"
  36. else
  37. echo "[WARN] Parse error. Skipping config entry '$server'."
  38. fi
  39. done < <(grep "^server\." "$ZK_CONF")