#!/bin/bash
# hzhub-monitor-admin 状态脚本

cd "$(dirname "$0")"

PID_FILE="logs/monitor-admin.pid"

if [ -f "$PID_FILE" ]; then
  PID=$(cat "$PID_FILE")
  if kill -0 "$PID" 2>/dev/null; then
    echo "========================================="
    echo " hzhub-monitor-admin 状态"
    echo "========================================="
    echo "状态: 🟢 运行中"
    echo "PID:  $PID"
    PORT=$(ss -tlnp 2>/dev/null | grep ":9090 " | head -1)
    if [ -n "$PORT" ]; then
      echo "端口: 9090"
    fi
    echo "地址: http://localhost:9090/admin"
    echo "账号: ruoyi / 123456"
    echo "========================================="
    exit 0
  fi
fi

PIDS=$(pgrep -f "hzhub-monitor-admin" 2>/dev/null)
if [ -n "$PIDS" ]; then
  echo "hzhub-monitor-admin is running. (PID: $PIDS)"
else
  echo "hzhub-monitor-admin is not running."
fi
