#!/bin/bash
# Fix pveproxy worker exit issues on R630-04
# Run this script on R630-04

set -e

echo "=== Diagnosing pveproxy worker exit issues ==="
echo ""

echo "1. Current pveproxy status:"
systemctl status pveproxy --no-pager -l | head -30
echo ""

echo "2. Recent pveproxy logs (last 50 lines):"
journalctl -u pveproxy --no-pager -n 50
echo ""

echo "3. Checking pveproxy configuration:"
ls -la /etc/pveproxy/ 2>/dev/null || echo "No /etc/pveproxy/ directory"
echo ""

echo "4. Checking for port conflicts:"
ss -tlnp | grep 8006 || echo "Port 8006 not in use"
echo ""

echo "5. Checking Proxmox cluster status:"
pvecm status 2>&1 || echo "Not in cluster or cluster check failed"
echo ""

echo "=== Attempting fixes ==="
echo ""

echo "6. Restarting pveproxy service:"
systemctl restart pveproxy
sleep 3

echo "7. Checking status after restart:"
systemctl status pveproxy --no-pager -l | head -30
echo ""

echo "8. Checking if port 8006 is now listening:"
ss -tlnp | grep 8006 || echo "Port 8006 still not listening"
echo ""

echo "=== If still failing, check these ==="
echo "- /var/log/pveproxy/access.log"
echo "- /var/log/pveproxy/error.log"
echo "- journalctl -u pveproxy -f (for real-time logs)"
echo "- Check if Proxmox VE packages are fully installed: dpkg -l | grep proxmox"

