Route remaining sudo call sites through hostd-call.sh / hostd:
- scripts/destroy-jails.sh: bastille stop/destroy via hostd-call.sh
- scripts/docs-sync.cron.sh: nginx reload via service-restart op
- scripts/heartbeat.sh: bastille list via hostd-call.sh
- src/startup-report.ts: drop sudo bastille/pkg fallbacks; tighten
buildStartupReport signature now that hostdData is always supplied
Relies on 537c613 (non-interactive bastille-destroy) so the
yes-pipe in destroy-jails.sh is no longer needed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
88 lines
2.5 KiB
Bash
88 lines
2.5 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..."
|
|
"${SCRIPT_DIR:-$(dirname "$0")}/hostd-call.sh" bastille-stop "{\"jail\":\"$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 | "${SCRIPT_DIR:-$(dirname "$0")}/hostd-call.sh" bastille-destroy "{\"jail\":\"$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"
|