diff --git a/core/docker/Dockerfile b/core/docker/Dockerfile index ae025a8ad21e..5827a04f3db9 100644 --- a/core/docker/Dockerfile +++ b/core/docker/Dockerfile @@ -35,3 +35,5 @@ EXPOSE 8080 USER trino:trino ENV LANG en_US.UTF-8 CMD ["/usr/lib/trino/bin/run-trino"] +HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \ + CMD /usr/lib/trino/bin/health-check diff --git a/core/docker/bin/health-check b/core/docker/bin/health-check new file mode 100755 index 000000000000..0f4d50b77a69 --- /dev/null +++ b/core/docker/bin/health-check @@ -0,0 +1,32 @@ +#!/bin/bash + +set -euo pipefail + +function get_property() { + grep "^$1=" "$2" | cut -d'=' -f2 +} + +scheme=http +port=8080 + +config=/etc/trino/config.properties +# prefer to use http even if https is enabled +if [ "$(get_property 'http-server.http.enabled' "$config")" == "false" ]; then + scheme=https + port=$(get_property http-server.https.port "$config") +else + port=$(get_property http-server.http.port "$config") +fi + +endpoint="$scheme://localhost:$port/v1/info" + +# add --insecure to disable certificate verification in curl, in case a self-signed certificate is being used +if ! info=$(curl --fail --silent --show-error --insecure "$endpoint"); then + echo >&2 "Server is not responding to requests" + exit 1 +fi + +if ! grep -q '"starting":\s*false' <<<"$info" >/dev/null; then + echo >&2 "Server is starting" + exit 1 +fi diff --git a/core/docker/container-test.sh b/core/docker/container-test.sh index 256f585b0e6b..08985dc3929c 100644 --- a/core/docker/container-test.sh +++ b/core/docker/container-test.sh @@ -20,7 +20,7 @@ function test_trino_starts { set +e I=0 - until RESULT=$(docker exec "${CONTAINER_ID}" trino --execute "SELECT 'success'" 2>/dev/null); do + until docker inspect "${CONTAINER_ID}" --format "{{json .State.Health.Status }}" | grep -q '"healthy"'; do if [[ $((I++)) -ge ${QUERY_RETRIES} ]]; then echo "🚨 Too many retries waiting for Trino to start" echo "Logs from ${CONTAINER_ID} follow..." @@ -29,6 +29,9 @@ function test_trino_starts { fi sleep ${QUERY_PERIOD} done + if ! RESULT=$(docker exec "${CONTAINER_ID}" trino --execute "SELECT 'success'" 2>/dev/null); then + echo "🚨 Failed to execute a query after Trino container started" + fi set -e cleanup