bb17615f41
SLICE-03 (devops-engineer): ported from coreci/scripts/proxmox/: api.sh (verbatim), ct-exists.sh, lxc-clone.sh (4GB/16GB, hostname=praxis), lxc-config.sh (praxis env vars, praxis-firstboot.sh snippet), lxc-start.sh, stage-snippet.sh (G-101 FIX: bakes GITEA_TOKEN into snippet via sed), timing.sh (verbatim), rollback.sh (proxy code removed) SLICE-04 (devops-engineer): health-check.sh adapted for /health:8789 (G-104 FIX: timeout bumped 300s→600s for Docker build margin) REQ-DEPLOY-03, 04, 05, 07, 08 covered. ---ci--- project: praxis phase: 1 milestone: v0.2 status: execute slice: 03-04 wave: 2 ---/ci---
58 lines
2.0 KiB
Bash
Executable File
58 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# Praxis — Rollback a failed LXC deployment.
|
|
#
|
|
# Stops (graceful, then force) and destroys the CT. Idempotent:
|
|
# a 404 (CT already gone) is not an error.
|
|
#
|
|
# Praxis v0.2 has no proxy/traefik tier, so there is no backend-route
|
|
# removal step here (unlike the coreci rollback which referenced
|
|
# PROXY_VMID and proxy/backend-remove.sh). If a proxy tier is added in
|
|
# a later slice, restore that step from coreci/scripts/proxmox/rollback.sh.
|
|
#
|
|
# Env: PROXMOX_API_URL, PROXMOX_API_TOKEN, PROXMOX_NODE
|
|
# Args: $1 = VMID
|
|
# Exit: 0 on success (including already-gone), 1 on failure
|
|
|
|
set -eu
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
# shellcheck source=api.sh disable=SC1091
|
|
. "${SCRIPT_DIR}/api.sh"
|
|
|
|
pve_env PROXMOX_API_URL PROXMOX_API_TOKEN PROXMOX_NODE
|
|
|
|
vmid="${1:?usage: rollback.sh <vmid>}"
|
|
node="${PROXMOX_NODE}"
|
|
|
|
echo "rollback: cleaning up VMID ${vmid}" >&2
|
|
|
|
# Graceful shutdown
|
|
shutdown_path="/nodes/${node}/lxc/${vmid}/status/shutdown"
|
|
upid=$(pve_curl POST "$shutdown_path" "timeoutStop=30" 2>/dev/null || true)
|
|
if [ -n "$upid" ] && [ "$upid" != "null" ]; then
|
|
pve_poll "$upid" 2>/dev/null || true
|
|
fi
|
|
|
|
# Check if still running; force stop if so
|
|
status=$(pve_get "/nodes/${node}/lxc/${vmid}/status/current" 2>/dev/null || true)
|
|
if [ -n "$status" ] && [ "$status" != "null" ]; then
|
|
running=$(printf '%s' "$status" | jq -r '.status' 2>/dev/null || true)
|
|
if [ "$running" = "running" ]; then
|
|
echo "rollback: force-stopping VMID ${vmid}" >&2
|
|
stop_path="/nodes/${node}/lxc/${vmid}/status/stop"
|
|
upid=$(pve_curl POST "$stop_path" 2>/dev/null || true)
|
|
if [ -n "$upid" ] && [ "$upid" != "null" ]; then
|
|
pve_poll "$upid" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Destroy (idempotent — 404 is fine)
|
|
echo "rollback: destroying VMID ${vmid}" >&2
|
|
destroy_path="/nodes/${node}/lxc/${vmid}"
|
|
upid=$(pve_curl DELETE "$destroy_path" 2>/dev/null || true)
|
|
if [ -n "$upid" ] && [ "$upid" != "null" ]; then
|
|
pve_poll "$upid" 2>/dev/null || true
|
|
fi
|
|
|
|
echo "rollback: VMID ${vmid} cleaned up" >&2 |