Files
my-project/config/openclaw/scripts/seo-health-check.sh
T

76 lines
2.0 KiB
Bash
Raw 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
# 守护者健康检查 v1.0 - SEO系统专用
# 基于4号机health-check-standardized.sh简化
LOG_DIR="/root/.openclaw/logs/health"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/health-$(date '+%Y%m%d').log"
log() { echo "[$(date '+%H:%M:%S')] $1" | tee -a "$LOG_FILE"; }
section() { echo ""; echo "=== $1 ==="; echo "=== $1 ===" >> "$LOG_FILE"; }
# 检查函数
check_gateway() {
section "Gateway"
if pgrep -f "openclaw.*gateway" > /dev/null 2>&1; then
local pid=$(pgrep -f "openclaw.*gateway" | head -1)
log "✅ Gateway运行中 (PID: $pid)"
else
log "❌ Gateway未运行"
fi
# 端口检查
if curl -s --noproxy 127.0.0.1 --max-time 5 http://127.0.0.1:18789 > /dev/null 2>&1; then
log "✅ 端口18789响应正常"
else
log "❌ 端口18789无响应"
fi
}
check_seo_tasks() {
section "SEO定时任务"
# 检查seo发布
if pgrep -f "seo.*publish\|seo.*monetizer" > /dev/null 2>&1; then
log "✅ SEO任务运行中"
else
log "ℹ️ SEO任务未运行(可能在等待)"
fi
# 检查crontab
local cron_count=$(crontab -l 2>/dev/null | grep -c "seo\|SEO" || echo "0")
log "ℹ️ SEO相关cron: ${cron_count}个"
}
check_resources() {
section "资源状态"
local cpu=$(top -bn1 2>/dev/null | awk 'NR==2 {print $2}' | sed 's/%Cpu(s)//')
local mem=$(free -h | awk 'NR==2 {print $3}')
local disk=$(df -h / | tail -1 | awk '{print $5}')
log "ℹ️ CPU: ${cpu}%"
log "ℹ️ 内存: ${mem}"
log "ℹ️ 磁盘: ${disk}"
}
check_openbjb() {
section "openbjb.com站点"
if curl -s --noproxy '*' --max-time 10 "https://openbjb.com" > /dev/null 2>&1; then
log "✅ openbjb.com 可访问"
else
log "❌ openbjb.com 连接失败"
fi
}
main() {
log "========== 守护者健康检查 =========="
check_gateway
check_seo_tasks
check_resources
check_openbjb
log "========== 健康检查完成 =========="
}
main