#!/usr/bin/env bash # Diagnose gpu-fan port conflicts and running instances. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STACK_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" OPT_ENV="/opt/control-plane/.env" REPO_ENV="${STACK_DIR}/../control-plane/.env" echo "=== gpu-fan status ===" echo "" if systemctl list-unit-files gpu-fan.service &>/dev/null; then echo "systemd:" systemctl is-active gpu-fan 2>/dev/null && systemctl status gpu-fan --no-pager -l 2>/dev/null | head -8 || echo " inactive" else echo "systemd: gpu-fan.service not installed" fi echo "" echo "Ports 8090–8099:" if ss -tlnp 2>/dev/null | grep -E ':809[0-9]' ; then : elif ss -tln 2>/dev/null | grep -E ':809[0-9]' ; then echo " (run as root for process names: sudo ss -tlnp)" else echo " (none listening)" fi echo "" echo "gpu-fan processes:" pgrep -af '/opt/gpu-fan/.venv/bin/python|stacks/gpu-fan/.venv/bin/python|gpu-fan/app.py' 2>/dev/null \ || echo " (none)" echo "" echo "Shell suspended jobs (Ctrl+Z):" if jobs -l 2>/dev/null | grep -q .; then jobs -l echo " Kill with: kill %" else echo " (none in this shell)" fi echo "" echo "GPU_FAN_API_PORT config:" [[ -f "${OPT_ENV}" ]] && echo " /opt/control-plane/.env: $(grep '^GPU_FAN_API_PORT=' "${OPT_ENV}" || echo '(not set)')" [[ -f "${REPO_ENV}" ]] && echo " repo control-plane: $(grep '^GPU_FAN_API_PORT=' "${REPO_ENV}" || echo '(not set)')" echo " Note: production uses /opt/control-plane/.env (shared with Server UI)" echo "" if [[ "${1:-}" == "--cleanup" ]]; then if [[ "${EUID}" -ne 0 ]]; then echo "ERROR: --cleanup requires root: sudo ${SCRIPT_DIR}/status.sh --cleanup" exit 1 fi echo "=== cleanup ===" systemctl stop gpu-fan 2>/dev/null || true pkill -f '/opt/gpu-fan/.venv/bin/python /opt/gpu-fan/app.py' 2>/dev/null || true pkill -f 'stacks/gpu-fan/.venv/bin/python app.py' 2>/dev/null || true sleep 0.5 if ss -tln 2>/dev/null | grep -qE ':809[0-9]'; then echo "WARNING: ports still in use:" ss -tlnp 2>/dev/null | grep -E ':809[0-9]' || ss -tln | grep -E ':809[0-9]' echo "Check suspended jobs in other shells: jobs -l" else echo "Ports 809x are free." fi echo "" echo "Start production instance:" echo " sudo systemctl start gpu-fan" echo "Or foreground debug (systemd stopped):" echo " sudo ${SCRIPT_DIR}/start.sh" fi