Files
douyin/backend/baota_status.sh
2026-07-17 09:24:47 +08:00

87 lines
3.0 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
# 宝塔/服务器快速诊断:服务是否在跑、端口是否监听
set -uo pipefail
BACKEND="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(cd "$BACKEND/.." && pwd)"
PORT="${KEFU_PORT:-8000}"
echo "========================================"
echo " 抖音客服 - 运行诊断"
echo "========================================"
echo
echo "[1] 端口 ${PORT} 监听状态:"
if command -v ss &>/dev/null; then
ss -tlnp | grep ":${PORT} " || echo " -> 未监听(服务未启动)"
elif command -v netstat &>/dev/null; then
netstat -tlnp 2>/dev/null | grep ":${PORT} " || echo " -> 未监听(服务未启动)"
else
echo " (无法检测,请安装 ss 或 netstat)"
fi
echo
echo "[2] Python 环境:"
BROKEN_BT="/home/www/server/pyporject_evn/versions/3.11.15/bin/python"
if [ -x "$BROKEN_BT" ] && ! "$BROKEN_BT" -c "import ssl" 2>/dev/null; then
echo " [X] 宝塔 Python 无 SSL(不可用): $BROKEN_BT"
echo " 修复: AUTO_BUILD_PYTHON=1 bash $ROOT/install.sh"
fi
if [ -f "$BACKEND/lib/resolve_python.sh" ]; then
# shellcheck source=lib/resolve_python.sh
source "$BACKEND/lib/resolve_python.sh"
if PY="$(resolve_python "$BACKEND" "$ROOT" 2>/dev/null)"; then
echo " Python: $PY"
"$PY" -V 2>&1 | sed 's/^/ /'
if "$PY" -c "import ssl" 2>/dev/null; then
"$PY" -c "import ssl; print(' SSL:', ssl.OPENSSL_VERSION)"
else
echo " SSL: 无(不可用)"
fi
if "$PY" -c "import uvicorn" 2>/dev/null; then
echo " uvicorn: 已安装"
else
echo " uvicorn: 未安装 -> 运行 bash $BACKEND/baota_fix.sh"
fi
else
echo " 未找到可用 Python 3.10+"
fi
else
command -v python && python -V || echo " 未找到 python"
fi
echo
echo "[3] 前端静态:"
if [ -f "$ROOT/frontend/dist/index.html" ]; then
echo " OK: $ROOT/frontend/dist/index.html"
else
echo " 缺失 -> 运行 bash $BACKEND/baota_init.sh"
fi
echo
echo "[4] 宝塔项目进程:"
ps aux 2>/dev/null | grep -E "uvicorn|douyin" | grep -v grep || echo " 未发现 uvicorn 进程"
echo
echo "[5] 防火墙(CentOS firewalld:"
if command -v firewall-cmd &>/dev/null && systemctl is-active firewalld &>/dev/null; then
firewall-cmd --list-ports 2>/dev/null | grep -q "${PORT}" \
&& echo " 端口 ${PORT} 已放行" \
|| echo " 端口 ${PORT} 未放行 -> firewall-cmd --add-port=${PORT}/tcp --permanent && firewall-cmd --reload"
else
echo " firewalld 未运行或未安装(可忽略,检查云服务器安全组)"
fi
echo
echo "========================================"
echo " 若端口未监听,按顺序执行:"
echo " 若宝塔 Python 无 SSL,必须先编译可用 Python:"
echo " AUTO_BUILD_PYTHON=1 bash $ROOT/install.sh"
echo " KEFU_PYTHON=/usr/local/python3.11/bin/python3.11 bash $BACKEND/baota_fix.sh"
echo " bash $BACKEND/baota_init.sh"
echo " 宝塔启动命令: bash $BACKEND/baota_start.sh"
echo
echo " 手动测试启动:"
echo " bash $BACKEND/baota_start.sh"
echo "========================================"