Skip to content

Commit 0ccf661

Browse files
Make start-cassandra health check platform-independent
1 parent b1ca7c1 commit 0ccf661

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.build/docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ RUN set -eux; \
4343
# https://github.com/apache/cassandra/blob/18bcda2d4c2eba7370a0b21f33eed37cb730bbb3/bin/cassandra#L90-L100
4444
# https://github.com/apache/cassandra/commit/604c0e87dc67fa65f6904ef9a98a029c9f2f865a
4545
numactl \
46+
# required for docker health-check
47+
netcat \
4648
; \
4749
rm -rf /var/lib/apt/lists/*; \
4850
# https://issues.apache.org/jira/browse/CASSANDRA-15767 ("bin/cassandra" only looks for "libjemalloc.so" or "libjemalloc.so.1" which doesn't match our "libjemalloc.so.2")
@@ -127,4 +129,8 @@ ENTRYPOINT ["docker-entrypoint.sh"]
127129
# 9042: CQL
128130
# 9160: thrift service
129131
EXPOSE 7000 7001 7199 9042 9160
132+
133+
# Check the daemon is listening on CQL/JMX ports
134+
HEALTHCHECK CMD /usr/bin/nc localhost -z 9042 && /usr/bin/nc localhost -z 7199 || exit 1
135+
130136
CMD ["cassandra", "-f"]

.build/docker/start.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ fi
4848
docker network create cassandra-test 2>/dev/null || true
4949

5050
CONTAINER_ID=`docker run --rm --name cassandra-test --network cassandra-test -d apache/cassandra-test`
51-
CONTAINER_IP=`docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_ID`
5251

53-
until nc -z $CONTAINER_IP 9042
52+
until [ "$( docker container inspect -f '{{.State.Health.Status}}' $CONTAINER_ID )" != "starting" ]
5453
do
55-
echo "Waiting for cassandra-test container $CONTAINER_ID to start listening on $CONTAINER_IP:9042..."
54+
echo "Waiting for cassandra-test container $CONTAINER_ID to start."
5655
sleep 5
5756
done
5857

59-
echo "cassandra-test container started with id $CONTAINER_ID and ip $CONTAINER_IP"
58+
if [ "$( docker container inspect -f '{{.State.Health.Status}}' $CONTAINER_ID )" != "healthy" ]; then
59+
echo "Cassandra test container $CONTAINER_ID started but is unhealty."
60+
exit 1
61+
fi
62+
63+
echo "cassandra-test container started with id $CONTAINER_ID"
6064
display_help

0 commit comments

Comments
 (0)