Skip to content

Commit afed99f

Browse files
committed
Healthcheck using Host and Port from zoo.cfg
Since it's getting more complex, I moved the healthcheck logic to its own script.
1 parent 557aa96 commit afed99f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ WORKDIR /opt/zookeeper
1818

1919
# Only checks if server is up and listening, not quorum.
2020
# See https://zookeeper.apache.org/doc/r3.4.13/zookeeperAdmin.html#sc_zkCommands
21-
HEALTHCHECK CMD [ $(echo ruok | nc 127.0.0.1:2181) == "imok" ] || exit 1
21+
COPY healthcheck /healthcheck
22+
HEALTHCHECK CMD /healthcheck
2223

2324
VOLUME ["/opt/zookeeper/conf", "/tmp/zookeeper"]
2425

healthcheck

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Read bound host and port from the config file (if any)
3+
set -e
4+
5+
CFG=/opt/zookeeper/conf/zoo.cfg
6+
if [ -e "$CFG" ]; then
7+
H="$(awk -F= '/^clientPortAddress=/{ print $2 }' "$CFG")"
8+
P="$(awk -F= '/^clientPort=/{ print $2 }' "$CFG")"
9+
fi
10+
11+
[ "$(echo ruok | nc "${H:-127.0.01}" "${P:-2181}")" == "imok" ] || exit 1

0 commit comments

Comments
 (0)