From 2f1c6307843c8e786528f3c8fe1ebf6f7d05bc40 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hoelt Date: Thu, 18 Oct 2018 07:53:17 +0000 Subject: [PATCH] Healthcheck using Host and Port from zoo.cfg Since it's getting more complex, I moved the healthcheck logic to its own script. --- Dockerfile | 3 ++- healthcheck | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100755 healthcheck diff --git a/Dockerfile b/Dockerfile index 31b836c..ac818bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,8 @@ WORKDIR /opt/zookeeper # Only checks if server is up and listening, not quorum. # See https://zookeeper.apache.org/doc/r3.4.13/zookeeperAdmin.html#sc_zkCommands -HEALTHCHECK CMD [ $(echo ruok | nc 127.0.0.1:2181) == "imok" ] || exit 1 +COPY healthcheck /healthcheck +HEALTHCHECK CMD /healthcheck VOLUME ["/opt/zookeeper/conf", "/tmp/zookeeper"] diff --git a/healthcheck b/healthcheck new file mode 100755 index 0000000..4680d77 --- /dev/null +++ b/healthcheck @@ -0,0 +1,11 @@ +#!/bin/bash +# Read bound host and port from the config file (if any) +set -e + +CFG=/opt/zookeeper/conf/zoo.cfg +if [ -e "$CFG" ]; then + H="$(awk -F= '/^clientPortAddress=/{ print $2 }' "$CFG")" + P="$(awk -F= '/^clientPort=/{ print $2 }' "$CFG")" +fi + +[ "$(echo ruok | nc "${H:-127.0.0.1}" "${P:-2181}")" == "imok" ] || exit 1