Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
142 lines
6.2 KiB
Bash
Executable File
142 lines
6.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# rollback.sh: move Menivor back from Neon to box 1 Postgres (MG9 rollback path).
|
|
# Runbook: infra-box/RUNBOOK-MENIVOR-NEON.md, "Rollback".
|
|
#
|
|
# rollback.sh --yes [--copy-back]
|
|
#
|
|
# 1. The stack must be on Neon (COMPOSE_FILE has docker-compose.neon.yml).
|
|
# 2. Stop the writers (api, worker, housekeeping, beat): downtime starts.
|
|
# 3. Start the box database container that cutover.sh stopped (its data was
|
|
# left as it was at the cutover).
|
|
# 4. verify.sh Neon -> box, exact.
|
|
# * Same data (no writes since the cutover): switch straight back.
|
|
# * Different data and no --copy-back: restart the writers on Neon, stop.
|
|
# Nothing changed; rerun with --copy-back.
|
|
# * Different data with --copy-back: the box database is RENAMED to
|
|
# reelforge_pre_rollback_<time> (kept, never dropped), a new empty
|
|
# reelforge is created, copy.sh Neon -> box, verify.sh exact again.
|
|
# 5. Switch the env file back (COMPOSE_FILE=docker-compose.yml; the previous
|
|
# file is kept as a .bak), start the stack, wait for /healthz: downtime ends.
|
|
# 6. Append to the origin-flip log. The Neon project is left untouched.
|
|
#
|
|
# If the box database files are gone (disk loss), this script cannot help: use
|
|
# the Neon branch restore (restore-drill.sh --mode neon-branch --at) or, as the
|
|
# last fallback, the box backups (backup/backup.sh dumps, wal-g M4.5 once set up).
|
|
set -Eeuo pipefail
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=lib.sh
|
|
. "$HERE/lib.sh"
|
|
|
|
usage() { sed -n '2,25p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 2; }
|
|
|
|
YES=0 COPY_BACK=0
|
|
while (($#)); do
|
|
case "$1" in
|
|
--yes) YES=1 ;;
|
|
--copy-back) COPY_BACK=1 ;;
|
|
-h | --help) usage ;;
|
|
*) echo "unknown argument: $1" >&2; usage ;;
|
|
esac
|
|
shift
|
|
done
|
|
((YES)) || usage
|
|
NCUT_HEALTH_TIMEOUT_S="${NCUT_HEALTH_TIMEOUT_S:-180}"
|
|
BOX_EP="container:$MENIVOR_DB_CONTAINER/$MENIVOR_DB_NAME"
|
|
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
REPORT_FILE="$NCUT_STATE_DIR/rollback-$STAMP.json"
|
|
STARTED_AT="$(ncut_now)"
|
|
NOTES=()
|
|
note() { NOTES+=("$*"); ncut_log "$*"; }
|
|
declare -A R=()
|
|
|
|
write_report() {
|
|
install -d -m 700 "$NCUT_STATE_DIR"
|
|
local args=() k
|
|
for k in "${!R[@]}"; do args+=(--arg "$k" "${R[$k]}"); done
|
|
jq -n --arg verdict "$1" --arg summary "$2" --arg started "$STARTED_AT" \
|
|
--arg notes "$(printf '%s\n' "${NOTES[@]+"${NOTES[@]}"}")" "${args[@]+"${args[@]}"}" \
|
|
'$ARGS.named | del(.notes) + {notes: ($notes | split("\n") | map(select(length > 0)))}
|
|
| with_entries(.value |= (if type == "string" and test("^-?[0-9]+$") then tonumber else . end))' \
|
|
>"$REPORT_FILE"
|
|
chmod 600 "$REPORT_FILE"
|
|
echo "ROLLBACK $1 $2 (report: $REPORT_FILE)"
|
|
}
|
|
|
|
WRITERS_STOPPED=0
|
|
ncut_on_die() {
|
|
[[ "$BASHPID" == "$$" ]] || exit 1
|
|
trap - ERR
|
|
if ((WRITERS_STOPPED)); then
|
|
note "failure: the env file still points at Neon; restarting the writers there"
|
|
# shellcheck disable=SC2086
|
|
ncut_compose start $NCUT_WRITERS >/dev/null 2>&1 || true
|
|
fi
|
|
write_report FAIL "$*" || true
|
|
}
|
|
trap 'ncut_die "unexpected error on line $LINENO"' ERR
|
|
|
|
[[ "$(ncut_db_target)" == neon ]] || ncut_die "the stack is not on Neon (COMPOSE_FILE has no docker-compose.neon.yml); nothing to roll back"
|
|
ncut_endpoint_check "$BOX_EP"
|
|
MENIVOR_NEON_DIRECT_URL="$(menivor_env_get MENIVOR_NEON_DIRECT_URL || true)"
|
|
export MENIVOR_NEON_DIRECT_URL
|
|
ncut_endpoint_check env:MENIVOR_NEON_DIRECT_URL
|
|
ncut_prepare_state_dir
|
|
R[work_dir]="$NCUT_WORK"
|
|
|
|
note "stopping writers: $NCUT_WRITERS"
|
|
WRITERS_STOPPED=1
|
|
t_stop=$SECONDS
|
|
R[writers_stopped_at]="$(ncut_now)"
|
|
# shellcheck disable=SC2086
|
|
ncut_compose stop $NCUT_WRITERS >&2
|
|
|
|
note "starting the box database $MENIVOR_DB_CONTAINER"
|
|
docker start "$MENIVOR_DB_CONTAINER" >/dev/null 2>&1 \
|
|
|| ncut_compose --profile box-db up -d db >&2 \
|
|
|| ncut_die "cannot start the box database"
|
|
ready=0
|
|
for _ in $(seq 1 60); do
|
|
if docker exec "$MENIVOR_DB_CONTAINER" pg_isready -U "$MENIVOR_DB_USER" -d "$MENIVOR_DB_NAME" >/dev/null 2>&1; then ready=1; break; fi
|
|
sleep 2
|
|
done
|
|
((ready)) || ncut_die "box database did not become ready"
|
|
|
|
if "$HERE/verify.sh" --source env:MENIVOR_NEON_DIRECT_URL --target "$BOX_EP" \
|
|
--report "$NCUT_WORK/verify-before.json" >&2; then
|
|
R[path]=switch
|
|
note "box database matches Neon: switching straight back"
|
|
else
|
|
rc=$?
|
|
((rc == 3)) || ncut_die "verify Neon -> box could not run (exit $rc)"
|
|
if ((!COPY_BACK)); then
|
|
ncut_die "Neon has changes since the cutover ($(jq -r '.mismatches | length' "$NCUT_WORK/verify-before.json") differences). Nothing was changed; rerun with --copy-back to copy Neon back to box 1"
|
|
fi
|
|
R[path]=copy-back
|
|
keep="${MENIVOR_DB_NAME}_pre_rollback_$STAMP"
|
|
keep="${keep,,}"
|
|
note "renaming box database $MENIVOR_DB_NAME to $keep (kept)"
|
|
ncut_pg "container:$MENIVOR_DB_CONTAINER/postgres" psql -X -v ON_ERROR_STOP=1 -q \
|
|
-c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$MENIVOR_DB_NAME' AND pid <> pg_backend_pid()" \
|
|
-c "ALTER DATABASE \"$MENIVOR_DB_NAME\" RENAME TO \"$keep\"" \
|
|
-c "CREATE DATABASE \"$MENIVOR_DB_NAME\" OWNER \"$MENIVOR_DB_USER\"" >/dev/null
|
|
R[kept_box_database]="$keep"
|
|
out="$("$HERE/copy.sh" --source env:MENIVOR_NEON_DIRECT_URL --target "$BOX_EP" --work "$NCUT_WORK")" \
|
|
|| ncut_die "copy Neon -> box failed; the old box data is in $keep"
|
|
for kv in $out; do case "$kv" in dump_bytes=* | dump_s=* | restore_s=*) R[${kv%%=*}]="${kv#*=}" ;; esac; done
|
|
"$HERE/verify.sh" --source env:MENIVOR_NEON_DIRECT_URL --target "$BOX_EP" \
|
|
--report "$NCUT_WORK/verify-after.json" >&2 \
|
|
|| ncut_die "verify after copy-back failed; see $NCUT_WORK/verify-after.json"
|
|
fi
|
|
|
|
note "switching the env file back to box 1"
|
|
menivor_env_set COMPOSE_FILE "$NCUT_COMPOSE_FILES_BOX" to-box
|
|
menivor_env_set MENIVOR_DB_TARGET box to-box
|
|
ncut_compose up -d >&2 || ncut_die "stack did not start on box 1"
|
|
ncut_wait_healthy "$NCUT_HEALTH_TIMEOUT_S" || ncut_die "api not healthy on box 1 after ${NCUT_HEALTH_TIMEOUT_S}s"
|
|
WRITERS_STOPPED=0
|
|
R[serving_at]="$(ncut_now)"
|
|
R[downtime_s]=$((SECONDS - t_stop))
|
|
install -d "$(dirname "$NCUT_FLIPS_LOG")"
|
|
printf '%s\tmenivor-db-rollback-to-box\n' "${R[serving_at]}" >>"$NCUT_FLIPS_LOG"
|
|
write_report PASS "Menivor serves from box 1 Postgres again (${R[path]}); downtime ${R[downtime_s]}s"
|