Add check_container_health helper, wired into mattermost.sh as reference

A service's "Started" message after docker compose up -d doesn't mean
the app is actually working — it can still crash-loop (bad DB
password, missing required env var, etc.) with no visible sign until
someone separately runs docker ps -a much later, exactly what happened
repeatedly this session (mattermost, koha-db, homebox, vaultwarden,
filebrowser all showed a clean "Started" message while crash-looping).

check_container_health (lib/common.sh) waits briefly, checks the
container's actual status and restart count via docker inspect, and
prints recent logs automatically if it's not running or has already
restarted — instead of a misleading one-line success message.

Wired into mattermost.sh's own start step as the reference
implementation, guarded by declare -F so standalone runs (no
lib/common.sh sourced) degrade gracefully. Not retrofitted across
every other service in one pass — this establishes the shared helper
so other services can adopt it incrementally.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn
This commit is contained in:
Claude
2026-08-11 03:24:50 +00:00
parent 74628f3736
commit ad011b2db8
2 changed files with 56 additions and 3 deletions
+13 -3
View File
@@ -742,9 +742,19 @@ MIGRATE_BODY
local START=""
prompt_yn "Start Mattermost now? (y/n):" "y" START
if [ "$START" = "y" ] || [ "$START" = "Y" ]; then
docker compose up -d \
&& log_success "Mattermost started" \
|| log_warning "Start failed — check: docker compose logs"
if docker compose up -d; then
log_success "Mattermost started"
# Reference implementation of the shared health check — a
# "Started" message alone doesn't mean the app is actually up;
# it can still crash-loop (bad DB password, missing required
# env var, etc.) with no visible sign until someone separately
# runs `docker ps -a` much later. Mattermost's own first DB
# connection attempt can take a few seconds, hence the longer
# wait than check_container_health's 8s default.
declare -F check_container_health >/dev/null 2>&1 && check_container_health "$MM_CONTAINER" 12
else
log_warning "Start failed — check: docker compose logs"
fi
fi
echo ""