boot_cluster.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. set -ex
  3. # Launch and wait for toxiproxy
  4. ${REPOSITORY_ROOT}/vagrant/run_toxiproxy.sh &
  5. while ! nc -q 1 localhost 2181 </dev/null; do echo "Waiting"; sleep 1; done
  6. while ! nc -q 1 localhost 9092 </dev/null; do echo "Waiting"; sleep 1; done
  7. # Launch and wait for Zookeeper
  8. for i in 1 2 3 4 5; do
  9. KAFKA_PORT=`expr $i + 9090`
  10. cd ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT} && bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
  11. done
  12. while ! nc -q 1 localhost 21805 </dev/null; do echo "Waiting"; sleep 1; done
  13. # Launch and wait for Kafka
  14. for i in 1 2 3 4 5; do
  15. KAFKA_PORT=`expr $i + 9090`
  16. cd ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT} && bash bin/kafka-server-start.sh -daemon config/server.properties
  17. done
  18. ps auxww | grep -i kafka
  19. N=10
  20. RC=1
  21. set +x
  22. printf "Waiting for Kafka to become available."
  23. for _ in $(seq 1 "$N"); do
  24. if nc -z 127.0.0.1 29095 </dev/null; then
  25. RC=0
  26. break
  27. fi
  28. printf "."
  29. sleep 1
  30. done
  31. printf "\n"
  32. if [ "$RC" -gt 0 ]; then
  33. echo 'Error: Kafka failed to startup' >&2
  34. find "${KAFKA_INSTALL_ROOT}" -name "server.log" -print0 | xargs tail -256
  35. exit ${RC}
  36. fi