confluent based image
[dmaap/kafka11aaf.git] / src / main / docker / include / etc / confluent / docker / configure
1 #!/usr/bin/env bash
2 #
3 # Copyright 2016 Confluent Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 . /etc/confluent/docker/bash-config
18
19 dub ensure KAFKA_ZOOKEEPER_CONNECT
20 dub ensure KAFKA_ADVERTISED_LISTENERS
21
22 # By default, LISTENERS is derived from ADVERTISED_LISTENERS by replacing
23 # hosts with 0.0.0.0. This is good default as it ensures that the broker
24 # process listens on all ports.
25 if [[ -z "${KAFKA_LISTENERS-}" ]]
26 then
27   export KAFKA_LISTENERS
28   KAFKA_LISTENERS=$(cub listeners "$KAFKA_ADVERTISED_LISTENERS")
29 fi
30
31 dub path /etc/kafka/ writable
32
33 if [[ -z "${KAFKA_LOG_DIRS-}" ]]
34 then
35   export KAFKA_LOG_DIRS
36   KAFKA_LOG_DIRS="/var/lib/kafka/data"
37 fi
38
39 # advertised.host, advertised.port, host and port are deprecated. Exit if these properties are set.
40 if [[ -n "${KAFKA_ADVERTISED_PORT-}" ]]
41 then
42   echo "advertised.port is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead."
43   exit 1
44 fi
45
46 if [[ -n "${KAFKA_ADVERTISED_HOST-}" ]]
47 then
48   echo "advertised.host is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead."
49   exit 1
50 fi
51
52 if [[ -n "${KAFKA_HOST-}" ]]
53 then
54   echo "host is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead."
55   exit 1
56 fi
57
58 if [[ -n "${KAFKA_PORT-}" ]]
59 then
60   echo "port is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead."
61   exit 1
62 fi
63
64 # Set if ADVERTISED_LISTENERS has SSL:// or SASL_SSL:// endpoints.
65 if [[ $KAFKA_ADVERTISED_LISTENERS == *"SSL://"* ]]
66 then
67   echo "SSL is enabled."
68
69   dub ensure KAFKA_SSL_KEYSTORE_FILENAME
70   export KAFKA_SSL_KEYSTORE_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEYSTORE_FILENAME"
71   dub path "$KAFKA_SSL_KEYSTORE_LOCATION" exists
72
73   dub ensure KAFKA_SSL_KEY_CREDENTIALS
74   KAFKA_SSL_KEY_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEY_CREDENTIALS"
75   dub path "$KAFKA_SSL_KEY_CREDENTIALS_LOCATION" exists
76   export KAFKA_SSL_KEY_PASSWORD
77   KAFKA_SSL_KEY_PASSWORD=$(cat "$KAFKA_SSL_KEY_CREDENTIALS_LOCATION")
78
79   dub ensure KAFKA_SSL_KEYSTORE_CREDENTIALS
80   KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEYSTORE_CREDENTIALS"
81   dub path "$KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION" exists
82   export KAFKA_SSL_KEYSTORE_PASSWORD
83   KAFKA_SSL_KEYSTORE_PASSWORD=$(cat "$KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION")
84
85   if [[ -n "${KAFKA_SSL_CLIENT_AUTH-}" ]] && ( [[ $KAFKA_SSL_CLIENT_AUTH == *"required"* ]] || [[ $KAFKA_SSL_CLIENT_AUTH == *"requested"* ]] )
86   then
87       dub ensure KAFKA_SSL_TRUSTSTORE_FILENAME
88       export KAFKA_SSL_TRUSTSTORE_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_TRUSTSTORE_FILENAME"
89       dub path "$KAFKA_SSL_TRUSTSTORE_LOCATION" exists
90
91       dub ensure KAFKA_SSL_TRUSTSTORE_CREDENTIALS
92       KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_TRUSTSTORE_CREDENTIALS"
93       dub path "$KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION" exists
94       export KAFKA_SSL_TRUSTSTORE_PASSWORD
95       KAFKA_SSL_TRUSTSTORE_PASSWORD=$(cat "$KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION")
96   fi
97   
98 fi
99
100 # Set if KAFKA_ADVERTISED_LISTENERS has SASL_PLAINTEXT:// or SASL_SSL:// endpoints.
101 if [[ $KAFKA_ADVERTISED_LISTENERS =~ .*SASL_.*://.* ]]
102 then
103   echo "SASL" is enabled.
104
105   dub ensure KAFKA_OPTS
106
107   if [[ ! $KAFKA_OPTS == *"java.security.auth.login.config"*  ]]
108   then
109     echo "KAFKA_OPTS should contain 'java.security.auth.login.config' property."
110   fi
111 fi
112
113 if [[ -n "${KAFKA_JMX_OPTS-}" ]]
114 then
115   if [[ ! $KAFKA_JMX_OPTS == *"com.sun.management.jmxremote.rmi.port"*  ]]
116   then
117     echo "KAFKA_OPTS should contain 'com.sun.management.jmxremote.rmi.port' property. It is required for accessing the JMX metrics externally."
118   fi
119 fi
120
121 dub template "/etc/confluent/docker/${COMPONENT}.properties.template" "/etc/${COMPONENT}/${COMPONENT}.properties"
122 dub template "/etc/confluent/docker/log4j.properties.template" "/etc/${COMPONENT}/log4j.properties"
123 dub template "/etc/confluent/docker/tools-log4j.properties.template" "/etc/${COMPONENT}/tools-log4j.properties"