zookeeper.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Start/stop a ZooKeeper quorum peer.
  20. USAGE="Usage: zookeeper.sh ((start|start-foreground) peer-id)|stop|stop-all"
  21. STARTSTOP=$1
  22. PEER_ID=$2
  23. if [[ $STARTSTOP != "start" ]] && [[ $STARTSTOP != "start-foreground" ]] && [[ $STARTSTOP != "stop" ]] && [[ $STARTSTOP != "stop-all" ]]; then
  24. echo $USAGE
  25. exit 1
  26. fi
  27. bin=`dirname "$0"`
  28. bin=`cd "$bin"; pwd`
  29. . "$bin"/config.sh
  30. ZK_CONF="$FLINK_CONF_DIR/zoo.cfg"
  31. if [ ! -f "$ZK_CONF" ]; then
  32. echo "[ERROR] No ZooKeeper configuration file found in '$ZK_CONF'."
  33. exit 1
  34. fi
  35. if [[ $STARTSTOP == "start" ]] || [[ $STARTSTOP == "start-foreground" ]]; then
  36. if [ -z $PEER_ID ]; then
  37. echo "[ERROR] Missing peer id argument. $USAGE."
  38. exit 1
  39. fi
  40. if [[ ! ${ZK_HEAP} =~ ${IS_NUMBER} ]]; then
  41. echo "[ERROR] Configured ZooKeeper JVM heap size is not a number. Please set '$KEY_ZK_HEAP_MB' in $FLINK_CONF_FILE."
  42. exit 1
  43. fi
  44. if [ "$ZK_HEAP" -gt 0 ]; then
  45. export JVM_ARGS="$JVM_ARGS -Xms"$ZK_HEAP"m -Xmx"$ZK_HEAP"m"
  46. fi
  47. # Startup parameters
  48. args=("--zkConfigFile" "${ZK_CONF}" "--peerId" "${PEER_ID}")
  49. fi
  50. # the JMX log4j integration in ZK 3.4 does not work log4j 2
  51. export JVM_ARGS="$JVM_ARGS -Dzookeeper.jmx.log4j.disable=true"
  52. if [[ $STARTSTOP == "start-foreground" ]]; then
  53. "${FLINK_BIN_DIR}"/flink-console.sh zookeeper "${args[@]}"
  54. else
  55. "${FLINK_BIN_DIR}"/flink-daemon.sh $STARTSTOP zookeeper "${args[@]}"
  56. fi