2 #*******************************************************************************
3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
20 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #*******************************************************************************
24 if [[ -z "$KAFKA_PORT" ]]; then
25 export KAFKA_PORT=9092
27 if [[ -z "$KAFKA_ADVERTISED_PORT" ]]; then
28 export KAFKA_ADVERTISED_PORT=$(docker port `hostname` $KAFKA_PORT | sed -r "s/.*:(.*)/\1/g")
30 if [[ -z "$KAFKA_BROKER_ID" ]]; then
31 # By default auto allocate broker ID
32 export KAFKA_BROKER_ID=1
34 if [[ -z "$KAFKA_LOG_DIRS" ]]; then
35 export KAFKA_LOG_DIRS="/kafka/kafka-logs-$HOSTNAME"
37 if [[ -z "$KAFKA_ZOOKEEPER_CONNECT" ]]; then
38 export KAFKA_ZOOKEEPER_CONNECT=$(env | grep ZK.*PORT_2181_TCP= | sed -e 's|.*tcp://||' | paste -sd ,)
41 if [[ -n "$KAFKA_HEAP_OPTS" ]]; then
42 sed -r -i "s/(export KAFKA_HEAP_OPTS)=\"(.*)\"/\1=\"$KAFKA_HEAP_OPTS\"/g" $KAFKA_HOME/bin/kafka-server-start.sh
46 if [[ -z "$KAFKA_ADVERTISED_HOST_NAME" && -n "$HOSTNAME_COMMAND" ]]; then
47 export KAFKA_ADVERTISED_HOST_NAME=$(eval $HOSTNAME_COMMAND)
52 if [[ $VAR =~ ^KAFKA_ && ! $VAR =~ ^KAFKA_HOME ]]; then
53 kafka_name=`echo "$VAR" | sed -r "s/KAFKA_(.*)=.*/\1/g" | tr '[:upper:]' '[:lower:]' | tr _ .`
54 env_var=`echo "$VAR" | sed -r "s/(.*)=.*/\1/g"`
55 if egrep -q "(^|^#)$kafka_name=" $KAFKA_HOME/config/server.properties; then
56 sed -r -i "s@(^|^#)($kafka_name)=(.*)@\2=${!env_var}@g" $KAFKA_HOME/config/server.properties #note that no config values may contain an '@' char
58 echo "$kafka_name=${!env_var}" >> $KAFKA_HOME/config/server.properties
63 if [[ -n "$CUSTOM_INIT_SCRIPT" ]] ; then
64 eval $CUSTOM_INIT_SCRIPT
70 # see https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86#.bh35ir4u5
72 echo 'Stopping Kafka....'
73 if [ $KAFKA_PID -ne 0 ]; then
74 kill -s TERM "$KAFKA_PID"
82 # Capture kill requests to stop properly
83 trap "term_handler" SIGHUP SIGINT SIGTERM
85 $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties &