123 lines
4.6 KiB
Bash
123 lines
4.6 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Start all stopped VMs and containers across all Proxmox hosts
|
||
|
|
# Checks all hosts and attempts to start any stopped services
|
||
|
|
|
||
|
|
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
|
||
|
|
|
||
|
|
|
||
|
|
# 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}[⚠]${NC} $1"; }
|
||
|
|
log_error() { echo -e "${RED}[✗]${NC} $1"; }
|
||
|
|
|
||
|
|
# Proxmox hosts
|
||
|
|
PROXMOX_HOSTS=("${PROXMOX_HOST_ML110:-192.168.11.10}" "${PROXMOX_HOST_R630_01:-192.168.11.11}" "${PROXMOX_HOST_R630_02:-192.168.11.12}")
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
|
|
echo "🚀 Start All Stopped Services"
|
||
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
total_started=0
|
||
|
|
total_failed=0
|
||
|
|
total_skipped=0
|
||
|
|
|
||
|
|
for host in "${PROXMOX_HOSTS[@]}"; do
|
||
|
|
log_info "Processing host: $host"
|
||
|
|
|
||
|
|
# Check if host is reachable
|
||
|
|
if ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "root@${host}" "echo 'connected'" 2>/dev/null >/dev/null; then
|
||
|
|
log_warn " Host $host is unreachable, skipping"
|
||
|
|
echo ""
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Get all stopped containers
|
||
|
|
stopped_containers=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "root@${host}" \
|
||
|
|
"pct list | grep stopped | awk '{print \$1}'" 2>/dev/null || echo "")
|
||
|
|
|
||
|
|
# Get all stopped VMs
|
||
|
|
stopped_vms=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "root@${host}" \
|
||
|
|
"qm list | grep stopped | awk '{print \$1}'" 2>/dev/null || echo "")
|
||
|
|
|
||
|
|
if [ -z "$stopped_containers" ] && [ -z "$stopped_vms" ]; then
|
||
|
|
log_success " No stopped services on $host"
|
||
|
|
echo ""
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Start stopped containers
|
||
|
|
if [ -n "$stopped_containers" ]; then
|
||
|
|
for vmid in $stopped_containers; do
|
||
|
|
log_info " Starting container $vmid..."
|
||
|
|
|
||
|
|
start_result=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "root@${host}" \
|
||
|
|
"pct start $vmid 2>&1" || echo "failed")
|
||
|
|
|
||
|
|
if echo "$start_result" | grep -qE "already running|started|OK"; then
|
||
|
|
log_success " ✓ Container $vmid started"
|
||
|
|
total_started=$((total_started + 1))
|
||
|
|
sleep 2
|
||
|
|
elif echo "$start_result" | grep -q "Configuration file.*does not exist"; then
|
||
|
|
log_warn " ⚠ Container $vmid: Config file missing (may need migration)"
|
||
|
|
total_skipped=$((total_skipped + 1))
|
||
|
|
else
|
||
|
|
log_error " ✗ Container $vmid failed: $(echo "$start_result" | head -1)"
|
||
|
|
total_failed=$((total_failed + 1))
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Start stopped VMs
|
||
|
|
if [ -n "$stopped_vms" ]; then
|
||
|
|
for vmid in $stopped_vms; do
|
||
|
|
log_info " Starting VM $vmid..."
|
||
|
|
|
||
|
|
start_result=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "root@${host}" \
|
||
|
|
"qm start $vmid 2>&1" || echo "failed")
|
||
|
|
|
||
|
|
if echo "$start_result" | grep -qE "already running|started|OK"; then
|
||
|
|
log_success " ✓ VM $vmid started"
|
||
|
|
total_started=$((total_started + 1))
|
||
|
|
sleep 3
|
||
|
|
else
|
||
|
|
log_error " ✗ VM $vmid failed: $(echo "$start_result" | head -1)"
|
||
|
|
total_failed=$((total_failed + 1))
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
done
|
||
|
|
|
||
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
|
|
log_info "Summary:"
|
||
|
|
log_success " Started: $total_started"
|
||
|
|
if [ $total_skipped -gt 0 ]; then
|
||
|
|
log_warn " Skipped: $total_skipped (config files missing)"
|
||
|
|
fi
|
||
|
|
if [ $total_failed -gt 0 ]; then
|
||
|
|
log_warn " Failed: $total_failed"
|
||
|
|
fi
|
||
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
if [ $total_started -gt 0 ]; then
|
||
|
|
log_info "Waiting for services to initialize..."
|
||
|
|
sleep 10
|
||
|
|
log_info "Services should now be running. Use 'list-all-vmids-final.sh' to verify."
|
||
|
|
fi
|