Files
floci/docker/healthcheck.sh
T
TATSUNO “Taz” Yasuhiro cc129007e4 perf(docker): cut healthy wait from 5 s to 0.1 s (#5447)
* perf(docker): cut healthy wait from 5 s to 0.1 s

* fix(docker): wait up to 5 s for ready hooks before reporting healthy

* fix(docker): build without pulling a Dockerfile frontend from Docker Hub
2026-10-11 22:07:24 -05:00

15 lines
700 B
Bash
Executable File

#!/bin/bash
# Container health probe. Bash only, because ubi9-micro has no curl.
exec 3<>/dev/tcp/127.0.0.1/4566 || exit 1
printf 'GET /_floci/init HTTP/1.0\r\nHost: localhost\r\n\r\n' >&3
IFS= read -r -d '' response <&3
[[ $response == "HTTP/1."?" 200"* ]] || exit 1
[[ $response == *'"ready":true'* ]] && exit 0
# Ready hooks still running. Report healthy 5 s after start anyway, as the first 5 s check always did,
# so a long hook never turns the container unhealthy.
read -r uptime _ < /proc/uptime
stat=$(< /proc/1/stat)
read -ra fields <<< "${stat##*) }"
# Field 22 of /proc/1/stat is the start time in clock ticks, 100 per second like the uptime digits.
(( ${uptime/./} - fields[19] >= 500 ))