clawdie-ai/scripts/destroy-jails.sh
Mevy Assistant b8fd655f02 Refactor V2 identity and platform ownership model
Make the multitenant branch use a clean PLATFORM_*/TENANT_* model, remove active AGENT_NAME runtime usage, collapse hostd ownership into the shared platform, add operator audit surfaces, and add read-only tenant lifecycle commands.

---
Build: pass | Tests: pass — 151 passed (14 files)
2026-04-24 07:49:09 +02:00

88 lines
2.4 KiB
Bash

#!/bin/sh
# Destroy all jails and prepare for clean rebuild
# Screenshot each step for documentation
set -e
PROJECT_ROOT="$(pwd)"
SCREENSHOT_DIR="${PROJECT_ROOT}/tmp/screenshots"
TIMESTAMP=$(date '+%Y%m%d-%H%M%S')
echo "=== Jail Destruction Script ==="
echo "Timestamp: $TIMESTAMP"
echo ""
# Function to screenshot
screenshot() {
local label="$1"
local file="${SCREENSHOT_DIR}/destroy-${label}-${TIMESTAMP}.txt"
script -q "$file" << 'CAPTURE'
EOF
echo "Screenshot: $file"
}
# 1. List current state
echo "=== Step 1: Current State ==="
echo "Jails:"
jls
echo ""
echo "ZFS datasets:"
zfs list -r zroot/clawdie-runtime/jails 2>/dev/null | head -20
echo ""
read -p "Continue with destruction? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo "Aborted."
exit 1
fi
# 2. Stop jails
echo ""
echo "=== Step 2: Stop Jails ==="
TENANT_ID=$(grep -m1 '^TENANT_ID=' .env 2>/dev/null | cut -d= -f2- | tr -d '"'"'" || true)
[ -n "$TENANT_ID" ] || TENANT_ID="clawdie"
for jail in "${TENANT_ID}-controlplane" "${TENANT_ID}-db"; do
if bastille list | grep -q "${jail}"; then
echo "Stopping $jail..."
sudo bastille stop "$jail" || echo " (already stopped)"
else
echo "$jail not running"
fi
done
# 3. Destroy jails
echo ""
echo "=== Step 3: Destroy Jails ==="
for jail in "${TENANT_ID}-controlplane" "${TENANT_ID}-db"; do
if [ -d "/usr/local/bastille/jails/${jail}" ]; then
echo "Destroying $jail..."
yes y | sudo bastille destroy "$jail" || echo " (error destroying, continuing)"
else
echo "$jail already destroyed"
fi
done
# 4. Verify ZFS datasets removed
echo ""
echo "=== Step 4: Verify Cleanup ==="
echo "Remaining jail datasets:"
zfs list -r zroot/clawdie-runtime/jails 2>/dev/null || echo "No jail datasets"
echo ""
echo "Remaining bastille directories:"
ls -la /usr/local/bastille/jails/ 2>/dev/null || echo "No bastille jails"
# 5. Clean up any stale epair interfaces
echo ""
echo "=== Step 5: Clean Network ==="
echo "Stale epair interfaces:"
ifconfig | grep -E "^epair|e0a_|e0b_" || echo "None found"
echo ""
echo "=== Destruction Complete ==="
echo ""
echo "Next steps:"
echo " 1. Update .env with new IPs"
echo " 2. Run: npm run wizard (or use existing .env)"
echo " 3. Run: sudo sh docs/internal/scripts/setup-db-jail.sh"
echo " 4. Run: sudo sh docs/internal/scripts/setup-controlplane-jail.sh"