diff --git a/kafka/scripts/start-kafka.sh b/kafka/scripts/start-kafka.sh index ff37918..0911b21 100755 --- a/kafka/scripts/start-kafka.sh +++ b/kafka/scripts/start-kafka.sh @@ -1,12 +1,13 @@ -#!/bin/sh +#!/bin/bash # Optional ENV variables: +# +# Any variable prefixed with KAFKA will be transformed to name of parameter for example +# KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false' will set auto.create.topic to false +# # * ADVERTISED_HOST: the external ip for the container, e.g. `docker-machine ip \`docker-machine active\`` # * ADVERTISED_PORT: the external port for Kafka, e.g. 9092 # * ZK_CHROOT: the zookeeper chroot that's used by Kafka (without / prefix), e.g. "kafka" -# * LOG_RETENTION_HOURS: the minimum age of a log file in hours to be eligible for deletion (default is 168, for 1 week) -# * LOG_RETENTION_BYTES: configure the size at which segments are pruned from the log, (default is 1073741824, for 1GB) -# * NUM_PARTITIONS: configure the default number of log partitions per topic # Configure advertised host/port if we run in helios if [ ! -z "$HELIOS_PORT_kafka" ]; then @@ -41,27 +42,25 @@ if [ ! -z "$ZK_CHROOT" ]; then sed -r -i "s/(zookeeper.connect)=(.*)/\1=localhost:2181\/$ZK_CHROOT/g" $KAFKA_HOME/config/server.properties fi -# Allow specification of log retention policies -if [ ! -z "$LOG_RETENTION_HOURS" ]; then - echo "log retention hours: $LOG_RETENTION_HOURS" - sed -r -i "s/(log.retention.hours)=(.*)/\1=$LOG_RETENTION_HOURS/g" $KAFKA_HOME/config/server.properties -fi -if [ ! -z "$LOG_RETENTION_BYTES" ]; then - echo "log retention bytes: $LOG_RETENTION_BYTES" - sed -r -i "s/#(log.retention.bytes)=(.*)/\1=$LOG_RETENTION_BYTES/g" $KAFKA_HOME/config/server.properties -fi +### START LICENSED CODE ### +# The following is copied from https://github.com/wurstmeister/kafka-docker/blob/master/start-kafka.sh +# under ASL v2 license -# Configure the default number of log partitions per topic -if [ ! -z "$NUM_PARTITIONS" ]; then - echo "default number of partition: $NUM_PARTITIONS" - sed -r -i "s/(num.partitions)=(.*)/\1=$NUM_PARTITIONS/g" $KAFKA_HOME/config/server.properties -fi +for VAR in `env` +do + if [[ $VAR =~ ^KAFKA_ && ! $VAR =~ ^KAFKA_HOME ]]; then + kafka_name=`echo "$VAR" | sed -r "s/KAFKA_(.*)=.*/\1/g" | tr '[:upper:]' '[:lower:]' | tr _ .` + env_var=`echo "$VAR" | sed -r "s/(.*)=.*/\1/g"` + if egrep -q "(^|^#)$kafka_name=" $KAFKA_HOME/config/server.properties; then + sed -r -i "s@(^|^#)($kafka_name)=(.*)@\2=${!env_var}@g" $KAFKA_HOME/config/server.properties #note that no config values may contain an '@' char + else + echo "$kafka_name=${!env_var}" >> $KAFKA_HOME/config/server.properties + fi + echo "$kafka_name=$env_var" + fi +done -# Enable/disable auto creation of topics -if [ ! -z "$AUTO_CREATE_TOPICS" ]; then - echo "auto.create.topics.enable: $AUTO_CREATE_TOPICS" - echo "auto.create.topics.enable=$AUTO_CREATE_TOPICS" >> $KAFKA_HOME/config/server.properties -fi +### END LICENSED CODE ### # Run Kafka $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties