From 687ac2d44bb5e53cbf1e677cbee007291cb5dd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20G=C3=89RARD?= Date: Tue, 18 Sep 2018 16:33:21 +0200 Subject: [PATCH] Docker: Waiting for jmx port to be open before starting the exporter --- docker/Dockerfile | 7 ++++++- docker/run.sh | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1879d74..3d4dab1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,8 +1,13 @@ -FROM openjdk:10.0.1-10-jre-slim-sid +FROM openjdk:10.0.2-13-jre-slim-sid ARG EXPORTER_VERSION=2.0.0 ARG EXPORTER_SHA512=7baa4e13f0a3c4228ba9d6cb848027f8837de0a0bc2a6b4fc3d8265e00a53fe926a6eac75a32a84de5e0771b355c1a8715dd46886c134710c6f26f477010b9d3 +RUN apt-get update && apt-get install -y --no-install-recommends \ + netcat \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + RUN mkdir -p /etc/cassandra_exporter /opt/cassandra_exporter ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /sbin/dumb-init ADD https://github.com/criteo/cassandra_exporter/releases/download/${EXPORTER_VERSION}/cassandra_exporter-${EXPORTER_VERSION}-all.jar /opt/cassandra_exporter/cassandra_exporter.jar diff --git a/docker/run.sh b/docker/run.sh index f92da12..2e87738 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -20,4 +20,12 @@ while IFS='=' read -r name value ; do fi done < <(env) +host=$(grep -m1 'host:' /etc/cassandra_exporter/config.yml | cut -d ':' -f2) +port=$(grep -m1 'host:' /etc/cassandra_exporter/config.yml | cut -d ':' -f3) + +while ! nc -z $host $port; do + echo "Waiting for Cassandra JMX to start on $host:$port" + sleep 1 +done + /sbin/dumb-init /usr/bin/java ${JVM_OPTS} -jar /opt/cassandra_exporter/cassandra_exporter.jar /etc/cassandra_exporter/config.yml