3588AdminBackend/scripts/deploy/status.sh
2026-02-25 11:00:55 +08:00

155 lines
4.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 3588AdminBackend 状态检查脚本
APP_NAME="managerd"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PID_FILE="$APP_DIR/$APP_NAME.pid"
CONFIG_PATH="$APP_DIR/config/managerd.json"
LOG_DIR="$APP_DIR/logs"
BIN_PATH="$APP_DIR/bin/$APP_NAME"
echo "========== 3588AdminBackend 状态 =========="
echo ""
echo "基本信息:"
echo " 应用目录: $APP_DIR"
echo " 二进制文件: $BIN_PATH"
echo " 配置文件: $CONFIG_PATH"
echo " 日志目录: $LOG_DIR"
# 检查二进制文件
if [ -f "$BIN_PATH" ]; then
echo " 二进制状态: ✅ 存在"
# 显示版本信息(如果程序支持)
VERSION=$($BIN_PATH -version 2>/dev/null || echo "")
if [ -n "$VERSION" ]; then
echo " 版本: $VERSION"
fi
else
echo " 二进制状态: ❌ 不存在"
fi
# 检查配置文件
if [ -f "$CONFIG_PATH" ]; then
echo " 配置文件: ✅ 存在"
# 显示关键配置
if command -v python3 &> /dev/null; then
LISTEN=$(python3 -c "import json; print(json.load(open('$CONFIG_PATH')).get('listen', 'N/A'))" 2>/dev/null)
DISCOVERY_PORT=$(python3 -c "import json; print(json.load(open('$CONFIG_PATH')).get('discovery_port', 'N/A'))" 2>/dev/null)
echo " 监听地址: $LISTEN"
echo " 发现端口: $DISCOVERY_PORT (UDP)"
fi
else
echo " 配置文件: ❌ 不存在"
fi
echo ""
echo "运行状态:"
# 检查进程
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo " 进程状态: 🟢 运行中"
echo " PID: $PID"
# 获取进程详细信息
if command -v ps &> /dev/null; then
echo ""
echo "进程详情:"
ps -p "$PID" -o pid,ppid,pcpu,pmem,rss,vsz,etime,cmd --headers 2>/dev/null | while read line; do
echo " $line"
done
fi
# 检查端口监听
echo ""
echo "网络监听:"
if command -v ss &> /dev/null; then
LISTENERS=$(ss -tlnp | grep "$PID" || true)
if [ -n "$LISTENERS" ]; then
echo "$LISTENERS" | while read line; do
echo " TCP: $line"
done
fi
UDP_LISTENERS=$(ss -ulnp | grep "$PID" || true)
if [ -n "$UDP_LISTENERS" ]; then
echo "$UDP_LISTENERS" | while read line; do
echo " UDP: $line"
done
fi
elif command -v netstat &> /dev/null; then
LISTENERS=$(netstat -tlnp 2>/dev/null | grep "$PID/" || true)
if [ -n "$LISTENERS" ]; then
echo "$LISTENERS" | while read line; do
echo " $line"
done
fi
fi
# 测试 API
echo ""
echo "API 测试:"
if command -v curl &> /dev/null; then
# 从配置文件中获取监听地址
if [ -f "$CONFIG_PATH" ]; then
API_URL="http://127.0.0.1:18080/api/devices"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL" 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "401" ]; then
echo " ✅ HTTP API 响应正常 (HTTP $HTTP_CODE)"
elif [ "$HTTP_CODE" = "000" ]; then
echo " ⚠️ 无法连接 HTTP API"
else
echo " HTTP API 响应: $HTTP_CODE"
fi
fi
fi
else
echo " 进程状态: 🔴 未运行 (PID 文件存在但进程不存在)"
echo " 建议: 删除过期的 PID 文件"
fi
else
# 尝试直接查找进程
PID=$(pgrep -f "^$BIN_PATH" | head -1)
if [ -n "$PID" ]; then
echo " 进程状态: 🟡 运行中 (无 PID 文件PID: $PID)"
echo " 建议: 重新创建 PID 文件: echo $PID > $PID_FILE"
else
echo " 进程状态: ⚫ 未运行"
fi
fi
# 日志信息
echo ""
echo "日志信息:"
if [ -d "$LOG_DIR" ]; then
LOG_FILES=$(ls -1 "$LOG_DIR"/*.log 2>/dev/null | head -5)
if [ -n "$LOG_FILES" ]; then
echo " 日志文件:"
ls -lh "$LOG_DIR"/*.log 2>/dev/null | tail -5 | while read line; do
echo " $line"
done
# 显示最后几行日志
NEWEST_LOG=$(ls -t "$LOG_DIR"/*.log 2>/dev/null | head -1)
if [ -n "$NEWEST_LOG" ]; then
echo ""
echo " 最新日志 ($NEWEST_LOG):"
tail -n 3 "$NEWEST_LOG" | while read line; do
echo " $line"
done
fi
else
echo " 无日志文件"
fi
else
echo " 日志目录不存在"
fi
echo ""
echo "========== 操作命令 =========="
echo " 启动: $SCRIPT_DIR/start.sh"
echo " 停止: $SCRIPT_DIR/stop.sh"
echo " 查看日志: tail -f $LOG_DIR/$APP_NAME.log"