#!/bin/bash # Write Server 健康检查脚本 # 用于 Docker 健康检查或监控系统 set -e # 配置 PORT=${PORT:-8016} HOST=${HOST:-127.0.0.1} TIMEOUT=${HEALTH_CHECK_TIMEOUT:-5} # 检查服务是否响应 check_health() { local url="http://${HOST}:${PORT}/api/stats" local response # 发送请求 response=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout "$TIMEOUT" --max-time "$TIMEOUT" "$url" 2>/dev/null || echo "000") # 检查响应状态码 if [ "$response" = "200" ]; then return 0 else return 1 fi } # 主检查逻辑 main() { if check_health; then echo "Health check passed" exit 0 else echo "Health check failed" exit 1 fi } main