seafile/docker/healthcheck.sh

34 lines
910 B
Bash

#!/usr/bin/env bash
# Container healthcheck for Seafile single-container stack
# Returns 0 if both Seahub (via nginx) and fileserver respond, non-zero otherwise.
set -Eeuo pipefail
curl_opts=(--silent --show-error --fail --location --connect-timeout 2 --max-time 5)
check_seahub() {
local code
code="$(curl "${curl_opts[@]}" -o /dev/null -w "%{http_code}" "http://127.0.0.1/accounts/login/")" || return 1
# Accept 2xx and 3xx
if [[ "${code}" =~ ^2[0-9]{2}$ || "${code}" =~ ^3[0-9]{2}$ ]]; then
return 0
fi
return 1
}
check_fileserver() {
# Try direct fileserver port first
if curl "${curl_opts[@]}" "http://127.0.0.1:8082/protocol-version" >/dev/null 2>&1; then
return 0
fi
# Fallback through nginx route
curl "${curl_opts[@]}" "http://127.0.0.1/seafhttp/protocol-version" >/dev/null 2>&1
}
main() {
check_seahub || exit 1
check_fileserver || exit 1
exit 0
}
main "$@"