blob: e07bf06f9e6d4716794f3e08201b13d3b00d603b [file] [log] [blame]
khenb95fe9a2016-10-05 11:15:25 -07001#!/bin/bash
2
3
4if [[ -z "$START_TIMEOUT" ]]; then
5 START_TIMEOUT=600
6fi
7
8start_timeout_exceeded=false
9count=0
10step=10
11while netstat -lnt | awk '$4 ~ /:'$KAFKA_PORT'$/ {exit 1}'; do
12 echo "waiting for kafka to be ready"
13 sleep $step;
14 count=$(expr $count + $step)
15 if [ $count -gt $START_TIMEOUT ]; then
16 start_timeout_exceeded=true
17 break
18 fi
19done
20
21if $start_timeout_exceeded; then
22 echo "Not able to auto-create topic (waited for $START_TIMEOUT sec)"
23 exit 1
24fi
25
26if [[ -n $KAFKA_CREATE_TOPICS ]]; then
27 IFS=','; for topicToCreate in $KAFKA_CREATE_TOPICS; do
28 echo "creating topics: $topicToCreate"
29 IFS=':' read -a topicConfig <<< "$topicToCreate"
30 JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partition ${topicConfig[1]} --topic "${topicConfig[0]}"
31 done
32fi