qiangdanxitong/scripts/health-check.sh

31 lines
733 B
Bash

#!/bin/bash
# 简易健康检查脚本
# Usage: ./scripts/health-check.sh http://localhost:8080/api
API_BASE=${1:-"http://localhost:8080/api"}
HEALTH_URL="${API_BASE%/}/system/health"
echo "Checking backend health from ${HEALTH_URL} ..."
response=$(curl -s -w "\n%{http_code}" "${HEALTH_URL}")
body=$(echo "$response" | head -n -1)
status=$(echo "$response" | tail -n 1)
if [ "$status" != "200" ]; then
echo "❌ Health check request failed, status code: $status"
echo "Response: $body"
exit 1
fi
db_up=$(echo "$body" | jq -r '.data.databaseUp' 2>/dev/null)
if [ "$db_up" = "true" ]; then
echo "✅ Database connection OK"
else
echo "❌ Database check failed"
fi
echo "$body" | jq '.' 2>/dev/null || echo "$body"