--- Build: pass | Tests: pass - 603 passed (44 files) --- Build: pass | Tests: pass — Tests 603 passed (603)
87 lines
2.3 KiB
Bash
87 lines
2.3 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 ==="
|
|
AGENT_NAME=$(grep -m1 '^AGENT_NAME=' .env 2>/dev/null | cut -d= -f2- | tr -d '"'"'" || echo "clawdie")
|
|
for jail in "${AGENT_NAME}-controlplane" "${AGENT_NAME}-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 "${AGENT_NAME}-controlplane" "${AGENT_NAME}-db"; do
|
|
if [ -d "/usr/local/bastille/jails/${jail}" ]; then
|
|
echo "Destroying $jail..."
|
|
echo "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"
|