Service Health Check
Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.
$ webtoolist --script http-health-check
Check URLs for expected status codes and response time.
httpcurlmonitoringnetworkDependencies: curl
#!/usr/bin/env bash
set -euo pipefail
expect="${EXPECT:-200}"
(($# > 0)) || { echo "usage: $0 URL [URL...]" >&2; exit 1; }
fail=0
for url in "$@"; do
read -r code seconds < <(
curl -sS -o /dev/null -w '%{http_code} %{time_total}\n' \
--max-time 10 --retry 1 "$url" || echo "000 0"
)
if [[ "$code" == "$expect" ]]; then
printf 'ok %s %ss %s\n' "$code" "$seconds" "$url"
else
printf 'fail %s %ss %s\n' "$code" "$seconds" "$url" >&2
fail=1
fi
done
exit "$fail"
./http-health-check https://example.com https://example.com/health
EXPECT=204 ./http-health-check https://api.example.com/ping
000 means curl could not complete the request — DNS, TLS, or timeout.Related scripts
Check systemd services and HTTP endpoints in one pass with a non-zero exit on failure.
Check whether TCP ports on a host are reachable, with a timeout.
Exit non-zero when any mounted filesystem exceeds a usage threshold.