34945b32d00babfcc2b9521681f40290d1856aae
[dmaap/kafka11aaf.git] / src / main / docker / create-topics.sh
1 #!/bin/bash
2
3
4 if [[ -z "$START_TIMEOUT" ]]; then
5     START_TIMEOUT=600
6 fi
7
8 start_timeout_exceeded=false
9 count=0
10 step=10
11 while 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
19 done
20
21 if $start_timeout_exceeded; then
22     echo "Not able to auto-create topic (waited for $START_TIMEOUT sec)"
23     exit 1
24 fi
25
26 if [[ -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         if [ ${topicConfig[3]} ]; then
31           JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partitions ${topicConfig[1]} --topic "${topicConfig[0]}" --config cleanup.policy="${topicConfig[3]}" --if-not-exists
32         else
33           JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partitions ${topicConfig[1]} --topic "${topicConfig[0]}" --if-not-exists
34         fi
35     done
36 fi