github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/kafka/scripts/start-kafka.sh (about)

     1  #!/bin/sh
     2  
     3  # Optional ENV variables:
     4  # * ADVERTISED_HOST: the external ip for the container, e.g. `docker-machine ip \`docker-machine active\``
     5  # * ADVERTISED_PORT: the external port for Kafka, e.g. 9092
     6  # * ZK_CHROOT: the zookeeper chroot that's used by Kafka (without / prefix), e.g. "kafka"
     7  # * LOG_RETENTION_HOURS: the minimum age of a log file in hours to be eligible for deletion (default is 168, for 1 week)
     8  # * LOG_RETENTION_BYTES: configure the size at which segments are pruned from the log, (default is 1073741824, for 1GB)
     9  # * NUM_PARTITIONS: configure the default number of log partitions per topic
    10  
    11  # Configure advertised host/port if we run in helios
    12  if [ ! -z "$HELIOS_PORT_kafka" ]; then
    13      ADVERTISED_HOST=`echo $HELIOS_PORT_kafka | cut -d':' -f 1 | xargs -n 1 dig +short | tail -n 1`
    14      ADVERTISED_PORT=`echo $HELIOS_PORT_kafka | cut -d':' -f 2`
    15  fi
    16  
    17  # Set the external host and port
    18  if [ ! -z "$ADVERTISED_HOST" ]; then
    19      echo "advertised host: $ADVERTISED_HOST"
    20      sed -r -i "s/#(advertised.host.name)=(.*)/\1=$ADVERTISED_HOST/g" $KAFKA_HOME/config/server.properties
    21  fi
    22  if [ ! -z "$ADVERTISED_PORT" ]; then
    23      echo "advertised port: $ADVERTISED_PORT"
    24      sed -r -i "s/#(advertised.port)=(.*)/\1=$ADVERTISED_PORT/g" $KAFKA_HOME/config/server.properties
    25  fi
    26  
    27  # Set the zookeeper chroot
    28  if [ ! -z "$ZK_CHROOT" ]; then
    29      # wait for zookeeper to start up
    30      until /usr/share/zookeeper/bin/zkServer.sh status; do
    31        sleep 0.1
    32      done
    33  
    34      # create the chroot node
    35      echo "create /$ZK_CHROOT \"\"" | /usr/share/zookeeper/bin/zkCli.sh || {
    36          echo "can't create chroot in zookeeper, exit"
    37          exit 1
    38      }
    39  
    40      # configure kafka
    41      sed -r -i "s/(zookeeper.connect)=(.*)/\1=localhost:2181\/$ZK_CHROOT/g" $KAFKA_HOME/config/server.properties
    42  fi
    43  
    44  # Allow specification of log retention policies
    45  if [ ! -z "$LOG_RETENTION_HOURS" ]; then
    46      echo "log retention hours: $LOG_RETENTION_HOURS"
    47      sed -r -i "s/(log.retention.hours)=(.*)/\1=$LOG_RETENTION_HOURS/g" $KAFKA_HOME/config/server.properties
    48  fi
    49  if [ ! -z "$LOG_RETENTION_BYTES" ]; then
    50      echo "log retention bytes: $LOG_RETENTION_BYTES"
    51      sed -r -i "s/#(log.retention.bytes)=(.*)/\1=$LOG_RETENTION_BYTES/g" $KAFKA_HOME/config/server.properties
    52  fi
    53  
    54  # Configure the default number of log partitions per topic
    55  if [ ! -z "$NUM_PARTITIONS" ]; then
    56      echo "default number of partition: $NUM_PARTITIONS"
    57      sed -r -i "s/(num.partitions)=(.*)/\1=$NUM_PARTITIONS/g" $KAFKA_HOME/config/server.properties
    58  fi
    59  
    60  # Run Kafka
    61  $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties
    62