Files
cma-management/check.sh

66 lines
2.0 KiB
Bash
Executable File
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.
#!/bin/bash
# 管理会计OS — 环境自检脚本
set -e
echo "===== CMA 环境自检 ====="
echo ""
# 1. 后端服务
echo "[1] 后端服务"
if systemctl is-active cma-backend &>/dev/null; then
echo " ✓ cma-backend 运行中"
else
echo " ✗ cma-backend 未运行"
fi
# 2. Nginx
echo "[2] Nginx"
if nginx -t 2>&1 | grep -q "successful"; then
echo " ✓ Nginx 配置正确"
else
echo " ✗ Nginx 配置有误"
fi
# 3. 数据库
echo "[3] 数据库"
# 2026-09-12 凭据治理:账号必须与口令同源(backend/.env 已切 cma_api),禁止硬编码账号名
CMA_DB_USER="${CMA_DB_USER:-$(grep -m1 '^CMA_DB_USER=' /root/cma-management/backend/.env 2>/dev/null | cut -d= -f2- | tr -d '"')}"
CMA_DB_PASS="${CMA_DB_PASS:-$(grep -m1 '^CMA_DB_PASS=' /root/cma-management/backend/.env 2>/dev/null | cut -d= -f2- | tr -d '"')}"
if [ -z "$CMA_DB_USER" ] || [ -z "$CMA_DB_PASS" ]; then
echo " ! 未取到 CMA_DB_USER/PASS(2026-09-12 凭据治理:无明文兜底),跳过直连自检"
elif mysql -u"$CMA_DB_USER" -p"$CMA_DB_PASS" -h127.0.0.1 cma -e "SELECT 1;" &>/dev/null; then
echo " ✓ MariaDB 连接正常"
else
echo " ✗ MariaDB 连接失败"
fi
# 4. API 检查
echo "[4] API 端点"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8010/health 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
echo " ✓ API /health 返回 200"
else
echo " ✗ API /health 返回 $HTTP_CODE"
fi
# 5. 线上前端
echo "[5] 线上前端"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://cma.sxbh.ltd/ 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
echo " ✓ https://cma.sxbh.ltd 返回 200"
else
echo " ✗ https://cma.sxbh.ltd 返回 $HTTP_CODE"
fi
# 6. 线上 API
echo "[6] 线上 API"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://cma.sxbh.ltd/api/cma/users 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
echo " ✓ /api/cma/users 返回 200"
else
echo " ✗ /api/cma/users 返回 $HTTP_CODE"
fi
echo ""
echo "===== 自检完成 ====="