Skip to content

Commit b114dd2

Browse files
authored
Add /tmp cleanup to Connect and MM2 startup scripts (#11874)
Signed-off-by: Jakub Scholz <www@scholzj.com>
1 parent eac4148 commit b114dd2

3 files changed

Lines changed: 75 additions & 69 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set +x
4+
5+
# Prepare hostname - for StrimziPodSets we use the Pod DNS name assigned through the headless service
6+
ADVERTISED_HOSTNAME=$(hostname -f | cut -d "." -f1-4)
7+
export ADVERTISED_HOSTNAME
8+
9+
# Create dir where keystores and truststores will be stored
10+
mkdir -p /tmp/kafka
11+
12+
# Generate and print the config file
13+
echo "Starting Kafka Connect with configuration:"
14+
tee /tmp/strimzi-connect.properties < "/opt/kafka/custom-config/kafka-connect.properties" | sed -e 's/sasl.jaas.config=.*/sasl.jaas.config=[hidden]/g'
15+
echo ""
16+
17+
# Disable Kafka's GC logging (which logs to a file)...
18+
export GC_LOG_ENABLED="false"
19+
20+
if [ -z "$KAFKA_LOG4J_OPTS" ]; then
21+
export KAFKA_LOG4J_OPTS="-Dlog4j2.configurationFile=$KAFKA_HOME/custom-config/log4j2.properties"
22+
fi
23+
24+
# We don't need LOG_DIR because we write no log files, but setting it to a
25+
# directory avoids trying to create it (and logging a permission denied error)
26+
export LOG_DIR="$KAFKA_HOME"
27+
28+
# Enable Prometheus JMX Exporter as Java agent
29+
if [ "$KAFKA_CONNECT_JMX_EXPORTER_ENABLED" = "true" ]; then
30+
KAFKA_OPTS="${KAFKA_OPTS} -javaagent:$(ls "$JMX_EXPORTER_HOME"/jmx_prometheus_javaagent*.jar)=9404:$KAFKA_HOME/custom-config/metrics-config.json"
31+
export KAFKA_OPTS
32+
fi
33+
34+
. ./set_kafka_jmx_options.sh "${STRIMZI_JMX_ENABLED}" "${STRIMZI_JMX_USERNAME}" "${STRIMZI_JMX_PASSWORD}"
35+
36+
# Enable Tracing agent (initializes tracing) as Java agent
37+
if [ "$STRIMZI_TRACING" = "jaeger" ] || [ "$STRIMZI_TRACING" = "opentelemetry" ]; then
38+
KAFKA_OPTS="$KAFKA_OPTS -javaagent:$(ls "$KAFKA_HOME"/libs/tracing-agent*.jar)=$STRIMZI_TRACING"
39+
export KAFKA_OPTS
40+
if [ "$STRIMZI_TRACING" = "opentelemetry" ] && [ -z "$OTEL_TRACES_EXPORTER" ]; then
41+
# auto-set OTLP exporter
42+
export OTEL_TRACES_EXPORTER="otlp"
43+
fi
44+
fi
45+
46+
if [ -n "$STRIMZI_JAVA_SYSTEM_PROPERTIES" ]; then
47+
export KAFKA_OPTS="${KAFKA_OPTS} ${STRIMZI_JAVA_SYSTEM_PROPERTIES}"
48+
fi
49+
50+
# Disable FIPS if needed
51+
if [ "$FIPS_MODE" = "disabled" ]; then
52+
export KAFKA_OPTS="${KAFKA_OPTS} -Dcom.redhat.fips=false"
53+
fi
54+
55+
# Configure heap based on the available resources if needed
56+
. ./dynamic_resources.sh
57+
58+
# Configure Garbage Collection logging
59+
. ./set_kafka_gc_options.sh
60+
61+
set -x
62+
63+
# starting Kafka server with final configuration
64+
exec /usr/bin/tini -w -e 143 -- "${KAFKA_HOME}/bin/connect-distributed.sh" /tmp/strimzi-connect.properties

docker-images/kafka-based/kafka/scripts/kafka_connect_run.sh

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,9 @@
22
set -e
33
set +x
44

5-
# Prepare hostname - for StrimziPodSets we use the Pod DNS name assigned through the headless service
6-
ADVERTISED_HOSTNAME=$(hostname -f | cut -d "." -f1-4)
7-
export ADVERTISED_HOSTNAME
5+
# Clean-up /tmp directory from files which might have remained from previous container restart
6+
# We ignore any errors which might be caused by files injected by different agents which we do not have the rights to delete
7+
rm -rfv /tmp/* || true
88

9-
# Create dir where keystores and truststores will be stored
10-
mkdir -p /tmp/kafka
11-
12-
# Generate and print the config file
13-
echo "Starting Kafka Connect with configuration:"
14-
tee /tmp/strimzi-connect.properties < "/opt/kafka/custom-config/kafka-connect.properties" | sed -e 's/sasl.jaas.config=.*/sasl.jaas.config=[hidden]/g'
15-
echo ""
16-
17-
# Disable Kafka's GC logging (which logs to a file)...
18-
export GC_LOG_ENABLED="false"
19-
20-
if [ -z "$KAFKA_LOG4J_OPTS" ]; then
21-
export KAFKA_LOG4J_OPTS="-Dlog4j2.configurationFile=$KAFKA_HOME/custom-config/log4j2.properties"
22-
fi
23-
24-
# We don't need LOG_DIR because we write no log files, but setting it to a
25-
# directory avoids trying to create it (and logging a permission denied error)
26-
export LOG_DIR="$KAFKA_HOME"
27-
28-
# Enable Prometheus JMX Exporter as Java agent
29-
if [ "$KAFKA_CONNECT_JMX_EXPORTER_ENABLED" = "true" ]; then
30-
KAFKA_OPTS="${KAFKA_OPTS} -javaagent:$(ls "$JMX_EXPORTER_HOME"/jmx_prometheus_javaagent*.jar)=9404:$KAFKA_HOME/custom-config/metrics-config.json"
31-
export KAFKA_OPTS
32-
fi
33-
34-
. ./set_kafka_jmx_options.sh "${STRIMZI_JMX_ENABLED}" "${STRIMZI_JMX_USERNAME}" "${STRIMZI_JMX_PASSWORD}"
35-
36-
# Enable Tracing agent (initializes tracing) as Java agent
37-
if [ "$STRIMZI_TRACING" = "jaeger" ] || [ "$STRIMZI_TRACING" = "opentelemetry" ]; then
38-
KAFKA_OPTS="$KAFKA_OPTS -javaagent:$(ls "$KAFKA_HOME"/libs/tracing-agent*.jar)=$STRIMZI_TRACING"
39-
export KAFKA_OPTS
40-
if [ "$STRIMZI_TRACING" = "opentelemetry" ] && [ -z "$OTEL_TRACES_EXPORTER" ]; then
41-
# auto-set OTLP exporter
42-
export OTEL_TRACES_EXPORTER="otlp"
43-
fi
44-
fi
45-
46-
if [ -n "$STRIMZI_JAVA_SYSTEM_PROPERTIES" ]; then
47-
export KAFKA_OPTS="${KAFKA_OPTS} ${STRIMZI_JAVA_SYSTEM_PROPERTIES}"
48-
fi
49-
50-
# Disable FIPS if needed
51-
if [ "$FIPS_MODE" = "disabled" ]; then
52-
export KAFKA_OPTS="${KAFKA_OPTS} -Dcom.redhat.fips=false"
53-
fi
54-
55-
# Configure heap based on the available resources if needed
56-
. ./dynamic_resources.sh
57-
58-
# Configure Garbage Collection logging
59-
. ./set_kafka_gc_options.sh
60-
61-
set -x
62-
63-
# starting Kafka server with final configuration
64-
exec /usr/bin/tini -w -e 143 -- "${KAFKA_HOME}/bin/connect-distributed.sh" /tmp/strimzi-connect.properties
9+
# Run the script shared between Connect and MirrorMaker 2
10+
exec ./kafka_connect_mm2_shared_run.sh

docker-images/kafka-based/kafka/scripts/kafka_mirror_maker_2_run.sh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
set -e
33
set +x
44

5+
# Clean-up /tmp directory from files which might have remained from previous container restart
6+
# We ignore any errors which might be caused by files injected by different agents which we do not have the rights to delete
7+
rm -rfv /tmp/* || true
8+
59
# Generate temporary keystore password
610
MIRRORMAKER_2_CERTS_STORE_PASSWORD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32)
711
export MIRRORMAKER_2_CERTS_STORE_PASSWORD
@@ -76,13 +80,5 @@ if [ -n "$KAFKA_MIRRORMAKER_2_CLUSTERS" ]; then
7680
echo "Preparing MirrorMaker 2 cluster truststores is complete"
7781
fi
7882

79-
if [ -n "$STRIMZI_JAVA_SYSTEM_PROPERTIES" ]; then
80-
export KAFKA_OPTS="${KAFKA_OPTS} ${STRIMZI_JAVA_SYSTEM_PROPERTIES}"
81-
fi
82-
83-
# Disable FIPS if needed
84-
if [ "$FIPS_MODE" = "disabled" ]; then
85-
export KAFKA_OPTS="${KAFKA_OPTS} -Dcom.redhat.fips=false"
86-
fi
87-
88-
exec ./kafka_connect_run.sh
83+
# Run the script shared between Connect and MirrorMaker 2
84+
exec ./kafka_connect_mm2_shared_run.sh

0 commit comments

Comments
 (0)