koopa-admin-log/scripts/taler-shared/goa-regio-ng/goa-901x-recreate.sh

88 lines
2.9 KiB
Bash
Executable file

#!/bin/bash
# Recreate goa-regio-ng publishing 0.0.0.0:9010-9015 (host Caddy untouched).
# Freigabe: live cutover restore / 901x replace. Rollback hacktivism = recreate from existing images.
set -euo pipefail
TS="$(date -u +%Y%m%dT%H%MZ)"
IMG="localhost/goa-regio-ng:901x-wired-${TS}"
NAME="goa-regio-ng"
LOG="/tmp/goa-901x-recreate-${TS}.log"
exec > >(tee -a "$LOG") 2>&1
echo "TS=$TS IMG=$IMG LOG=$LOG"
echo "=== pre: CTR/ports ==="
podman ps -a --format '{{.Names}}\t{{.Status}}\t{{.Ports}}' | grep -E 'goa-regio|hacktivism' || true
ss -lntp 2>/dev/null | grep -E ':901[0-5]\b' || echo '(host 901x none)'
echo "=== save hacktivism CreateCommand (rollback recipe) ==="
ROLLBACK="/tmp/hacktivism-rollback-create-${TS}.txt"
: >"$ROLLBACK"
for c in taler-hacktivism-bank taler-hacktivism taler-hacktivism-exchange-ansible; do
if podman container exists "$c" 2>/dev/null; then
echo "--- $c ---" >>"$ROLLBACK"
podman inspect "$c" --format '{{json .Config.CreateCommand}}' >>"$ROLLBACK"
echo >>"$ROLLBACK"
podman inspect "$c" --format 'ImageName={{.ImageName}} ImageID={{.Image}}' >>"$ROLLBACK"
echo >>"$ROLLBACK"
fi
done
echo "ROLLBACK_FILE=$ROLLBACK"
echo "=== commit $NAME -> $IMG ==="
podman commit --pause=false "$NAME" "$IMG"
podman images "$IMG" --format '{{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}'
echo "=== free 901x: rm exited hacktivism CTRs (images kept) ==="
for c in taler-hacktivism-bank taler-hacktivism taler-hacktivism-exchange-ansible; do
if podman container exists "$c" 2>/dev/null; then
st="$(podman inspect "$c" --format '{{.State.Status}}')"
echo "rm $c (was $st)"
podman rm "$c"
else
echo "skip missing $c"
fi
done
echo "=== stop+rm old $NAME ==="
podman stop -t 30 "$NAME" || true
podman rm "$NAME"
echo "=== run $NAME from $IMG publishing 9010-9015 + lab 9180/9322 ==="
podman run -d \
--name "$NAME" \
--privileged \
--systemd=always \
--network pasta \
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
--tmpfs /run \
--tmpfs /run/lock \
-p 127.0.0.1:9322:22 \
-p 127.0.0.1:9180:80 \
-p 0.0.0.0:9010-9015:9010-9015 \
--hostname "$NAME" \
"$IMG" \
/sbin/init
echo "=== wait systemd + services ==="
sleep 8
for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
if podman exec -u root "$NAME" systemctl is-system-running --wait 2>/dev/null | grep -qE 'running|degraded'; then
break
fi
sleep 2
done
echo "=== host ports ==="
podman ps --filter "name=^${NAME}$" --format '{{.Names}}\t{{.Status}}\t{{.Ports}}'
ss -lntp 2>/dev/null | grep -E ':901[0-5]\b' || echo '(WARN host 901x none)'
echo "=== in-CTR listeners + units ==="
podman exec -u root "$NAME" bash -c '
ss -lntp 2>/dev/null | grep -E ":901[0-5]\b|:19096\b" || true
for u in nginx taler-exchange-httpd libeufin-bank goa-demo-withdraw-api postgresql; do
printf "%s=%s\n" "$u" "$(systemctl is-active "$u" 2>/dev/null || echo missing)"
done
'
echo "RECREATE_OK IMG=$IMG LOG=$LOG ROLLBACK=$ROLLBACK"