Files
kevinveenbirkenbachandClaude Opus 5 575a5a87ac refactor(layout): sort shipped scripts by language and split the unit suite
Every script a role ships now lives under `files/<language>/`, and the unit
suite is split the same way: `tests/unit/python/` beside new sibling trees for
the other languages. `tests/lint/filesystem/test_role_files_layout.py` keeps it
that way; directories whose shape is dictated from outside carry a `.nocheck`
naming the constraint (Docker build contexts, WordPress mu-plugins, the Joomla
extension, Odoo addons, Playwright suites, the `files/test/test.sh` harness
that `test-e2e-cli` resolves generically).

This cannot be applied in halves. Moving a file and repointing what names it
are the same change: 14 references resolve only at deploy time, so the tree is
green either before or after, never between.

Those 14 were found by static resolution over every reference class, not by the
test suite -- a full `make quality-high` was green while all of them were
broken:

  * 7 `src:` values built from a role variable holding a bare filename
    (svc-bkp-remote-2-local, decidim, espocrm, friendica, joomla, pixelfed x2).
    The variable doubles as the destination name inside the container, so the
    language segment belongs at the call site, not in the variable.
  * `sys-service/tasks/04_base.yml` resolved every consumer's systemd script
    through `first_found(..., errors='strict')` over `files/script.{sh,py}`.
    18 roles ship exactly that and have no template fallback: the play would
    have died on each.
  * `sys-front-inj-javascript` fell back to `<role>/files/javascript.js`; the
    interface now reads `files/javascript/javascript.js`.
  * `sys-front-inj-logout/templates/head_sub.j2` built the cache-busting mtime
    path through `path_absolute(... 'files', ...)`.
  * 4 `ansible.builtin.script:` invocations naming a bare command
    (pull.py, prune.sh, set_postgres_superuser_password.sh, ganesha-serve.sh).
  * `dev-python/files/shell/install.sh` pointed at a sibling role's script.

Depth-dependent paths inside the moved trees were bumped accordingly: 59
`parents[N]` computations, 12 relative climbs, and the per-role recover CLI,
whose path `cli/administration/recover/recoverers.py` still assembled from the
pre-move location.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 01:31:09 +02:00

120 lines
4.6 KiB
Bash

#!/bin/sh
docker_ps_grep_unhealthy="$(container ps --filter health=unhealthy --format '{{.Names}}')"
docker_ps_grep_exited="$(container ps --filter status=exited --format '{{.ID}}')"
swarm_state="$(container info --format '{{.Swarm.LocalNodeState}}' 2>/dev/null || echo inactive)"
is_manager="$(container info --format '{{.Swarm.ControlAvailable}}' 2>/dev/null || echo false)"
exitcode=0
summary=""
if [ -n "$docker_ps_grep_unhealthy" ]; then
echo "❌ Some docker containers are unhealthy:"
echo "$docker_ps_grep_unhealthy"
echo
for container_name in $docker_ps_grep_unhealthy
do
echo "------------------------------------------------------------"
echo "🔍 Last 200 log lines for unhealthy container: $container_name"
echo "------------------------------------------------------------"
container logs --tail 200 "$container_name" 2>&1 || echo "⚠️ Failed to fetch logs for $container_name"
echo
summary="$summary\n - $container_name (unhealthy)"
done
if [ "$exitcode" -lt 1 ]; then
exitcode=1
fi
fi
if [ "$swarm_state" != "active" ] && [ -n "$docker_ps_grep_exited" ]; then
for container_id in $docker_ps_grep_exited
do
container_exit_code="$(container inspect --type container "$container_id" --format='{{.State.ExitCode}}')"
container_name="$(container inspect --type container "$container_id" --format='{{.Name}}')"
container_name="${container_name#/}"
if [ "$container_exit_code" -ne "0" ]; then
echo "❌ Container $container_name exited with code $container_exit_code"
echo "------------------------------------------------------------"
echo "🔍 Last 200 log lines for exited container: $container_name"
echo "------------------------------------------------------------"
container logs --tail 200 "$container_name" 2>&1 || echo "⚠️ Failed to fetch logs for $container_name"
echo
summary="$summary\n - $container_name (exited: $container_exit_code)"
if [ "$exitcode" -lt 2 ]; then
exitcode=2
fi
fi
done
fi
if command -v container >/dev/null 2>&1; then
if [ "$swarm_state" = "active" ] && [ "$is_manager" = "true" ]; then
swarm_candidates="$(container service ls --format '{{.Name}} {{.Replicas}}' 2>/dev/null \
| awk '{
split($2, a, "/");
if (a[1] != a[2]) {
print $1 " " $2;
}
}')"
swarm_problems=""
while read -r service_name replicas; do
[ -z "$service_name" ] && continue
task_states="$(container service ps --no-trunc "$service_name" --format '{{.Name}}|{{.DesiredState}}|{{.CurrentState}}' 2>/dev/null)"
if printf '%s\n' "$task_states" | awk -F'|' '
!seen[$1]++ {
if ($2 ~ /Running/ || $2 ~ /Ready/) pending = 1
else if ($2 ~ /Shutdown/ && $3 ~ /Complete/) done_ok = 1
else bad = 1
}
END { exit (done_ok && !pending && !bad) ? 0 : 1 }'; then
continue
fi
swarm_problems="${swarm_problems:+$swarm_problems
}$service_name $replicas"
done <<EOF
$swarm_candidates
EOF
if [ -n "$swarm_problems" ]; then
echo "❌ Swarm services not fully converged:"
echo "$swarm_problems"
echo
while read -r service_name replicas; do
echo "------------------------------------------------------------"
echo "🔍 Recent tasks for swarm service: $service_name ($replicas)"
echo "------------------------------------------------------------"
container service ps --no-trunc "$service_name" 2>&1 | head -20 \
|| echo "⚠️ Failed to fetch tasks for $service_name"
summary="$summary\n - $service_name (swarm replicas $replicas)"
done <<EOF
$swarm_problems
EOF
if [ "$exitcode" -lt 1 ]; then
exitcode=1
fi
fi
fi
fi
if [ "$exitcode" -ne "0" ]; then
echo "============================================================"
echo "🚨 SUMMARY: Unhealthy / Failed Docker Containers"
echo "============================================================"
if [ -n "$summary" ]; then
printf "%b\n" "$summary"
else
echo " - (no details collected)"
fi
echo "============================================================"
exit $exitcode
fi
echo "✅ All docker containers are healthy."
exit 0