interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / spark / edge-http-rollback.sh

27 lines · 1872 bytes Raw Blame History
1#!/usr/bin/env bash
2# Undo spark/edge-http-apply.sh: restore the firewall file from the backup, load it, remove the files
3# the apply added (NEW_FILES), `nginx -t`, reload nginx. Run as root on the Spark:
4# sudo bash infra/spark/edge-http-rollback.sh /etc/nginx/forge-backups/http80-<UTC>
5# With no argument it uses the newest http80-* backup.
6set -uo pipefail
7NFT=${EDGE_NFT:-/etc/atlas/ingress.nft}
8BKROOT=${EDGE_BKROOT:-/etc/nginx/forge-backups}
9BK=${1:-$(ls -1d "$BKROOT"/http80-* 2>/dev/null | sort | tail -n 1)}
10die() { echo "edge-http-rollback: FAIL: $*" >&2; exit 1; }
11[ "$(id -u)" = 0 ] || die "run as root (sudo)"
12[ -n "$BK" ] && [ -f "$BK/ingress.nft" ] && [ -f "$BK/NEW_FILES" ] || die "no usable backup '$BK'"
13nft -c -f "$BK/ingress.nft" || die "backup firewall file fails nft -c; nothing changed"
14install -m 600 "$BK/ingress.nft" "$NFT"
15nft -f "$NFT" || die "nft -f of the restored file failed"
16while IFS= read -r f; do
17 [ -n "$f" ] || continue
18 case "$f" in /etc/nginx/sites-enabled/http-redirect|"${EDGE_SITE_DST:-/etc/nginx/sites-enabled/http-redirect}") rm -f -- "$f" ;;
19 *) echo "edge-http-rollback: not removing unexpected path $f" >&2 ;; esac
20done < "$BK/NEW_FILES"
21nginx -t -q 2>/dev/null || die "nginx -t fails after removing the redirect site"
22# A failed reload must not be reported as success: the site file is already gone, but the
23# running nginx may still be serving the redirect.
24${EDGE_RELOAD:-systemctl reload nginx} || die "nginx reload failed after the redirect site was removed; running nginx may not match disk"
25cmp -s "$NFT" "$BK/ingress.nft" || die "firewall file differs from the backup after restore"
26if nft list chain inet atlas_ingress http80_redirect > /dev/null 2>&1; then die "chain http80_redirect still live"; fi
27echo "edge-http-rollback: restored $NFT from $BK (byte-identical), redirect site removed, nginx reloaded"