interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / hub / forge-edge-rollback.sh

30 lines · 1760 bytes Raw Blame History
1#!/usr/bin/env bash
2# Undo forge-edge-apply.sh on the hub: restore the three edited files from the backup dir,
3# remove the files the apply created, `nginx -t`, reload, check the static sites.
4# Usage: sudo bash forge-edge-rollback.sh [/etc/nginx/forge-backups/<UTC>] (default: newest)
5set -u
6N=/etc/nginx
7BK=${1:-$(ls -1d $N/forge-backups/*/ 2>/dev/null | sort | tail -1)}
8BK=${BK%/}
9[ "$(id -u)" = 0 ] || { echo "run with sudo" >&2; exit 1; }
10[ -n "$BK" ] && [ -s "$BK/sites-enabled_interplane.io" ] && [ -s "$BK/sites-enabled_aienos.com" ] && [ -s "$BK/stream.d_sni-router.conf" ] \
11 || { echo "ROLLBACK: no usable backup in '$BK'" >&2; exit 1; }
12echo "rolling back from $BK"
13cp -a "$BK/sites-enabled_interplane.io" $N/sites-enabled/interplane.io
14cp -a "$BK/sites-enabled_aienos.com" $N/sites-enabled/aienos.com
15cp -a "$BK/stream.d_sni-router.conf" $N/stream.d/sni-router.conf
16while read -r f; do [ -n "$f" ] && rm -f -- "$f"; done < "$BK/NEW_FILES"
17for f in conf.d/forge.conf snippets/forge-proxy.conf snippets/forge-headers.conf snippets/forge-archive.conf snippets/aienos-forge.conf; do
18 b="$BK/$(echo "$f" | tr / _)"; [ -e "$b" ] && cp -a "$b" "$N/$f"
19done
20nginx -t || { echo "ROLLBACK: nginx -t fails on restored files; nginx NOT reloaded (old config still running)" >&2; exit 1; }
21${FORGE_RELOAD:-systemctl reload nginx} # FORGE_RELOAD: only for the container rehearsal
22sleep 2
23rc=0
24for u in https://interplane.io/ https://www.aienos.com/ https://hs.aienos.com/health; do
25 h=${u#https://}; h=${h%%/*}
26 c=$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 --resolve "$h:443:127.0.0.1" "$u")
27 echo "$c $u"; [ "$c" = 200 ] || rc=1
28done
29[ $rc = 0 ] && echo "ROLLBACK OK" || echo "ROLLBACK: a site check failed (see above)" >&2
30exit $rc