#!/bin/bash # Helper script for providing a docker compose healthcheck to containers that are healthy with # a non-200 status code. # # Usage: # ./healthcheck.sh url expected_response_code # # Example in docker compose expecting http://localhost:9999 to respond with a 401: # ``` # healthcheck: # test: ./healthcheck.sh http://localhost:9999 401 # ``` url=$1 expected_status_code=$2 status_code=$(curl --write-out %{http_code} --silent --output /dev/null $url) if [[ "$status_code" -eq $expected_status_code ]]; then exit 0 fi exit 1