khen | b95fe9a | 2016-10-05 11:15:25 -0700 | [diff] [blame] | 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 | 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 |
| 32 | fi |