Files
hometown/check-service.sh
2026-03-08 17:23:00 +08:00

31 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
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.
#!/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 ---"
# 独立后端路由为 /config无 /api 前缀Nginx 反代后浏览器请求 /api/config
if command -v curl >/dev/null 2>&1; then
resp=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/config" 2>/dev/null)
if [ "$resp" = "200" ]; then
echo "GET /config 返回 200服务正常。"
else
echo "GET /config 返回 ${resp},请检查服务。"
fi
else
echo "未安装 curl仅检查了端口监听。"
fi