Files
proxmox/scripts/archive/consolidated/fix/fix-all-pve2-container-issues.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

260 lines
11 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fix all remaining container issues on pve2
# Usage: ./scripts/fix-all-pve2-container-issues.sh
set -euo pipefail
# Load IP configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
PVE2_IP="${PROXMOX_HOST_R630_01}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
echo ""
log_info "Fixing all container issues on pve2..."
echo ""
# Check SSH
if ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} "echo 'OK'" &>/dev/null; then
log_error "Cannot access pve2"
exit 1
fi
FIXED=0
FAILED=0
# ============================================================================
# FIX 1: Disk Number Mismatches
# ============================================================================
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "FIX 1: Disk Number Mismatches"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
declare -A DISK_FIXES=(
[3000]="vm-3000-disk-1:vm-3000-disk-0"
[3001]="vm-3001-disk-1:vm-3001-disk-0"
[3002]="vm-3002-disk-2:vm-3002-disk-0"
[3003]="vm-3003-disk-1:vm-3003-disk-0"
[3500]="vm-3500-disk-1:vm-3500-disk-0"
[3501]="vm-3501-disk-2:vm-3501-disk-0"
[6400]="vm-6400-disk-1:vm-6400-disk-0"
)
for vmid in "${!DISK_FIXES[@]}"; do
log_info "Fixing CT $vmid disk number..."
IFS=':' read -r wrong_name correct_name <<< "${DISK_FIXES[$vmid]}"
# Get current config
rootfs_config=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct config $vmid 2>/dev/null | grep '^rootfs:'" || echo "")
if [[ -z "$rootfs_config" ]]; then
log_warn " Config missing, skipping..."
continue
fi
# Check if config has wrong disk number
if echo "$rootfs_config" | grep -q "$wrong_name"; then
# Extract storage pool and size
storage_pool=$(echo "$rootfs_config" | sed 's/^rootfs: //' | cut -d':' -f1)
size=$(echo "$rootfs_config" | grep -oP 'size=\K[^,]+' || echo "")
# Update config
if [[ -n "$size" ]]; then
new_rootfs="${storage_pool}:${correct_name},size=${size}"
else
new_rootfs="${storage_pool}:${correct_name}"
fi
log_info " Updating: $wrong_name$correct_name"
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set $vmid -rootfs $new_rootfs" 2>&1 >/dev/null; then
log_success " ✓ Config updated"
# Try to start
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start $vmid" 2>&1 >/dev/null; then
log_success " ✓ Container started"
((FIXED++))
else
log_warn " ⚠️ Start failed (may have other issues)"
((FAILED++))
fi
else
log_error " ❌ Failed to update config"
((FAILED++))
fi
else
log_info " Config already correct, attempting start..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start $vmid" 2>&1 >/dev/null; then
log_success " ✓ Container started"
((FIXED++))
else
log_warn " ⚠️ Start failed"
((FAILED++))
fi
fi
echo ""
done
# ============================================================================
# FIX 2: Pre-start Hook Failures
# ============================================================================
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "FIX 2: Pre-start Hook Failures"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
HOOK_FAILURE_CONTAINERS=(6000 10000 10001 10020 10030 10040 10050 10060 10070 10080 10090 10091 10092 10100 10101 10120 10130 10150 10151 10200 10201 10202 10210 10230)
log_info "Checking hook configuration for affected containers..."
# Check what hook is configured
for vmid in "${HOOK_FAILURE_CONTAINERS[@]}"; do
log_info "Fixing CT $vmid hook issue..."
# Check if hookscript is set
hook_config=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct config $vmid 2>/dev/null | grep '^hookscript:'" || echo "")
if [[ -n "$hook_config" ]]; then
hook_script=$(echo "$hook_config" | sed 's/^hookscript: //')
log_info " Hook script: $hook_script"
# Check if script exists
script_exists=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"test -f $hook_script && echo 'exists' || echo 'missing'" || echo "error")
if [[ "$script_exists" == "missing" ]]; then
log_warn " Hook script missing, removing hook..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set $vmid -delete hookscript" 2>&1 >/dev/null; then
log_success " ✓ Hook removed"
else
log_error " ❌ Failed to remove hook"
((FAILED++))
continue
fi
else
log_info " Hook script exists, checking permissions..."
# Try to disable hook temporarily
log_info " Disabling hook..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set $vmid -hookscript none" 2>&1 >/dev/null; then
log_success " ✓ Hook disabled"
else
log_warn " ⚠️ Could not disable hook, trying to remove..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set $vmid -delete hookscript" 2>&1 >/dev/null || true
fi
fi
else
log_info " No hook configured, checking for hook files..."
# Check for hook files in container directory
hook_files=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"ls -la /var/lib/lxc/$vmid/scripts/ 2>/dev/null | grep -E 'pre-start|post-start' || echo ''" || echo "")
if [[ -n "$hook_files" ]]; then
log_warn " Found hook files, removing..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"rm -f /var/lib/lxc/$vmid/scripts/pre-start /var/lib/lxc/$vmid/scripts/post-start 2>/dev/null" || true
log_success " ✓ Hook files removed"
fi
fi
# Try to start
log_info " Attempting to start container..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start $vmid" 2>&1 >/dev/null; then
log_success " ✓ Container started"
((FIXED++))
else
error=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start $vmid 2>&1" || true)
if echo "$error" | grep -q "already running"; then
log_success " ✓ Container already running"
((FIXED++))
else
log_warn " ⚠️ Start failed:"
echo "$error" | sed 's/^/ /' | head -2
((FAILED++))
fi
fi
echo ""
done
# ============================================================================
# FIX 3: Lock Issue
# ============================================================================
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "FIX 3: Lock Issue (CT 10232)"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "Clearing lock for CT 10232..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"rm -f /var/lock/qemu-server/lock-10232 /var/lock/qemu-server/lxc-10232 2>/dev/null" || true
sleep 2
# Also check for hook issues
hook_config=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct config 10232 2>/dev/null | grep '^hookscript:'" || echo "")
if [[ -n "$hook_config" ]]; then
log_info "Removing hook for CT 10232..."
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set 10232 -delete hookscript" 2>&1 >/dev/null || \
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct set 10232 -hookscript none" 2>&1 >/dev/null || true
fi
log_info "Attempting to start CT 10232..."
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start 10232" 2>&1 >/dev/null; then
log_success "✓ CT 10232 started"
((FIXED++))
else
error=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct start 10232 2>&1" || true)
log_warn "Start failed:"
echo "$error" | sed 's/^/ /' | head -3
((FAILED++))
fi
echo ""
# ============================================================================
# SUMMARY
# ============================================================================
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
log_info "SUMMARY"
log_info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
log_info "Fixed/Started: $FIXED"
log_info "Failed: $FAILED"
echo ""
# Check final status
log_info "Final container status:"
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${PVE2_IP} \
"pct list 2>/dev/null | grep -E '^[[:space:]]*(3000|3001|3002|3003|3500|3501|5200|6000|6400|10000|10001|10020|10030|10040|10050|10060|10070|10080|10090|10091|10092|10100|10101|10120|10130|10150|10151|10200|10201|10202|10210|10230|10232)[[:space:]]' | awk '{printf \" CT %s: %s\\n\", \$1, \$2}'" || true
echo ""
log_success "Fix script complete!"