diff options
author | lj1412 <lji@research.att.com> | 2017-02-14 13:08:07 +0000 |
---|---|---|
committer | lj1412 <lji@research.att.com> | 2017-02-14 13:08:09 +0000 |
commit | dd7aeafdb1d7596c1e825c7c12b2ab672bba25b9 (patch) | |
tree | 3940b973ba9f7a1014ebfde125938c9ba0b1e6f8 /docker_files/create-topics.sh | |
parent | 5a71eb2ee585d917e941e4cea886a2f90c628083 (diff) |
init
Change-Id: I4578bf7bc6b1b8a1f74730c01b47bb3f3371f2be
Signed-off-by: lj1412 <lji@research.att.com>
Diffstat (limited to 'docker_files/create-topics.sh')
-rw-r--r-- | docker_files/create-topics.sh | 32 |
1 files changed, 32 insertions, 0 deletions
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 |