From dd7aeafdb1d7596c1e825c7c12b2ab672bba25b9 Mon Sep 17 00:00:00 2001 From: lj1412 Date: Tue, 14 Feb 2017 13:08:07 +0000 Subject: init Change-Id: I4578bf7bc6b1b8a1f74730c01b47bb3f3371f2be Signed-off-by: lj1412 --- docker_files/create-topics.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docker_files/create-topics.sh (limited to 'docker_files/create-topics.sh') diff --git a/docker_files/create-topics.sh b/docker_files/create-topics.sh new file mode 100644 index 0000000..e07bf06 --- /dev/null +++ b/docker_files/create-topics.sh @@ -0,0 +1,32 @@ +#!/bin/bash + + +if [[ -z "$START_TIMEOUT" ]]; then + START_TIMEOUT=600 +fi + +start_timeout_exceeded=false +count=0 +step=10 +while netstat -lnt | awk '$4 ~ /:'$KAFKA_PORT'$/ {exit 1}'; do + echo "waiting for kafka to be ready" + sleep $step; + count=$(expr $count + $step) + if [ $count -gt $START_TIMEOUT ]; then + start_timeout_exceeded=true + break + fi +done + +if $start_timeout_exceeded; then + echo "Not able to auto-create topic (waited for $START_TIMEOUT sec)" + exit 1 +fi + +if [[ -n $KAFKA_CREATE_TOPICS ]]; then + IFS=','; for topicToCreate in $KAFKA_CREATE_TOPICS; do + echo "creating topics: $topicToCreate" + IFS=':' read -a topicConfig <<< "$topicToCreate" + JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partition ${topicConfig[1]} --topic "${topicConfig[0]}" + done +fi -- cgit 1.2.3-korg