Files
hx-ki.com2/com2_apply.sh
2026-03-06 15:22:40 +00:00

85 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
F="/opt/hx-ki/com2-stack/docker-compose.yml"
NET="hxki-internal"
echo "=== HXKI · COM2 APPLY (one-shot) ==="
# 0) Autorität muss existieren
[ -f "$F" ] || { echo "FEHLT: $F"; exit 1; }
# 1) Host-Caddy aus (damit Docker-Caddy 80/443 bekommt)
if systemctl is-active --quiet caddy 2>/dev/null; then
echo "[1] Stoppe host-caddy (systemd)"
systemctl stop caddy
fi
# 2) hxki-internal sicherstellen
if ! docker network ls --format '{{.Name}}' | grep -q "^${NET}$"; then
echo "[2] Erzeuge Netzwerk: $NET"
docker network create "$NET" >/dev/null
fi
# 3) PATCH nur im mautic->depends_on: mariadb -> hxki-mariadb (Mapping+List Form)
echo "[3] Patch: mautic depends_on mariadb -> hxki-mariadb (nur im depends_on Block)"
cp -a "$F" "${F}.bak.$(date +%Y%m%d-%H%M%S)"
awk '
function indent(s){ match(s,/^[ ]*/); return RLENGTH }
BEGIN{ in_mautic=0; in_dep=0; }
{
line=$0; ind=indent(line);
# enter mautic block
if (line ~ /^[ ]{2}mautic:[ ]*$/) { in_mautic=1; in_dep=0; print line; next; }
# leave mautic block when next 2-space service starts
if (in_mautic && ind==2 && line ~ /^[ ]{2}[A-Za-z0-9_.-]+:[ ]*$/ && line !~ /^[ ]{2}mautic:[ ]*$/) {
in_mautic=0; in_dep=0;
}
# enter depends_on inside mautic
if (in_mautic && line ~ /^[ ]{4}depends_on:[ ]*$/) { in_dep=1; print line; next; }
# leave depends_on when indentation back to 4 with a new key
if (in_dep && ind<=4 && line ~ /^[ ]{4}[A-Za-z0-9_.-]+:/) { in_dep=0; }
# patch mapping-form: " mariadb:" -> " hxki-mariadb:"
if (in_dep && line ~ /^[ ]+mariadb:[ ]*$/) { sub(/mariadb:/,"hxki-mariadb:",line); print line; next; }
# patch list-form: " - mariadb" -> " - hxki-mariadb"
if (in_dep && line ~ /^[ ]*-[ ]*mariadb[ ]*$/) { sub(/-[ ]*mariadb/,"- hxki-mariadb",line); print line; next; }
print line;
}
' "$F" > "${F}.tmp" && mv "${F}.tmp" "$F"
# 4) VALIDATE (das ist die Wahrheit)
echo "[4] Validate: docker compose config"
docker compose -f "$F" config >/dev/null
echo "OK: Compose ist valide."
# 5) UP (Orchester hoch)
echo "[5] Orchester hochfahren"
docker compose -f "$F" up -d --remove-orphans
# 6) Checks (Terminal-Ausgabe)
echo
echo "=== CHECKS ==="
echo "[A] Container (hxki*)"
docker ps --format 'NAME={{.Names}} STATUS={{.Status}} PORTS={{.Ports}}' | grep -E '^(hxki|hx-)' || true
echo
echo "[B] hxki-internal Mitglieder"
docker network inspect "$NET" --format '{{range $id,$c := .Containers}}{{println $c.Name}}{{end}}' | sort
echo
echo "[C] n8n basic (Port 5678 im Container erreichbar?)"
if docker ps --format '{{.Names}}' | grep -q '^hxki-n8n$'; then
docker exec -it hxki-n8n sh -lc 'wget -qO- http://127.0.0.1:5678/ >/dev/null && echo OK_N8N_LOCAL || echo FAIL_N8N_LOCAL' || true
fi
echo
echo "=== ENDE · COM2 APPLY ==="