fix: 优化启动脚本

This commit is contained in:
Daniel
2026-03-08 00:03:14 +08:00
parent 7db497bc94
commit 321fad8a0d
4 changed files with 64 additions and 3 deletions

29
check-service.sh Normal file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# 检查本项目的 Node 服务是否启动(默认 API 端口 5599
# 用法: ./check-service.sh [端口],不传端口则用 5599
PORT="${1:-5599}"
echo "检查端口 ${PORT} 是否在监听..."
if command -v ss >/dev/null 2>&1; then
ss -tlnp | grep -E ":$PORT\s" || true
elif command -v netstat >/dev/null 2>&1; then
netstat -tlnp 2>/dev/null | grep -E ":$PORT\s" || true
fi
if ! ss -tlnp 2>/dev/null | grep -q ":$PORT "; then
if ! netstat -tlnp 2>/dev/null | grep -q ":$PORT "; then
echo "端口 ${PORT} 未在监听,服务可能未启动。"
echo "启动方式: ./start-api.sh 或 ./run.sh"
exit 1
fi
fi
echo "--- 测试 API ---"
if command -v curl >/dev/null 2>&1; then
resp=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/api/config" 2>/dev/null)
if [ "$resp" = "200" ]; then
echo "GET /api/config 返回 200服务正常。"
else
echo "GET /api/config 返回 ${resp},请检查服务。"
fi
else
echo "未安装 curl仅检查了端口监听。"
fi