Skip to content

Instantly share code, notes, and snippets.

@smuthali
Last active November 9, 2016 01:46
Show Gist options
  • Save smuthali/fd2562f704bca761641006d40800348f to your computer and use it in GitHub Desktop.
Save smuthali/fd2562f704bca761641006d40800348f to your computer and use it in GitHub Desktop.
Kafka Consul template
#!/bin/bash
set -x
BROKERID={{ range $i, $services := service "zookeeper" }}{{ with node }}{{ if eq $services.Node .Node.Node }}{{ $i }}{{ end }}{{ end }}{{ end }}
HOSTNAME={{ range $i, $services := service "zookeeper" }}{{ with node }}{{ if eq $services.Node .Node.Node }}{{ $services.Address }}{{ end }}{{ end }}{{ end }}
ZOOKEEPER_CONNECT={{ range $i, $services := service "zookeeper" }}{{printf "%s:2181," $services.Address}}{{ end }}
KAFKA_CONNECT={{ range $i, $services := service "zookeeper" }}{{printf "%s:9092," $services.Address}}{{ end }}
sed -r -i "s/(zookeeper.connect)=(.*)/\1=$ZOOKEEPER_CONNECT/g" $KAFKA_HOME/config/server.properties
sed -r -i 's/(zookeeper.connect)=(.*)(.$)/\1=\2''/g' $KAFKA_HOME/config/server.properties
sed -r -i "s/(zookeeper.connect)=(.*)/\1=$ZOOKEEPER_CONNECT/g" $KAFKA_HOME/config/consumer.properties
sed -r -i 's/(zookeeper.connect)=(.*)(.$)/\1=\2''/g' $KAFKA_HOME/config/consumer.properties
sed -r -i "s/(broker.id)=(.*)/\1=$BROKERID/g" $KAFKA_HOME/config/server.properties
sed -r -i "s/(metadata.broker.list)=(.*)/\1=$KAFKA_CONNECT/g" $KAFKA_HOME/config/producer.properties
sed -r -i 's/(metadata.broker.list)=(.*)(.$)/\1=\2''/g' $KAFKA_HOME/config/producer.properties
echo
$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment