Files
plm-test-service/heartbeat-updater.sh
2026-04-10 21:22:35 +08:00

60 lines
1.7 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
# HEARTBEAT.md 自动更新脚本
# 由运营官部署 - 每30分钟自动更新
WORKSPACE="/home/serveradmin/.openclaw/workspace-qa-engineer"
HEARTBEAT_FILE="$WORKSPACE/HEARTBEAT.md"
LOG_FILE="/home/serveradmin/.openclaw/logs/heartbeat-update.log"
DATE=$(date '+%Y-%m-%d %H:%M')
# 确保日志目录存在
mkdir -p /home/serveradmin/.openclaw/logs
# 检查Gitea仓库状态
check_gitea() {
# 检查Gitea服务是否可访问
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/v1/user 2>/dev/null | grep -q "200\|401"; then
echo "✅ 正常"
else
echo "⚠️ 异常"
fi
}
# 检查OpenClaw Gateway状态
check_gateway() {
if openclaw gateway status 2>/dev/null | grep -q "running\|active"; then
echo "✅ 运行中"
else
echo "⚠️ 需检查"
fi
}
# 获取活跃会话数
get_active_sessions() {
# 从gateway-monitor.log获取最新会话数
if [ -f "/home/serveradmin/.openclaw/logs/gateway-monitor.log" ]; then
tail -1 /home/serveradmin/.openclaw/logs/gateway-monitor.log 2>/dev/null | grep -oP '会话:\K[0-9]+' || echo "未知"
else
echo "未知"
fi
}
# 更新HEARTBEAT.md
update_heartbeat() {
GITEA_STATUS=$(check_gitea)
GATEWAY_STATUS=$(check_gateway)
ACTIVE_SESSIONS=$(get_active_sessions)
# 更新时间戳
sed -i "s/_最后更新.*$/_最后更新$DATE (自动更新)/" "$HEARTBEAT_FILE"
# 记录日志
echo "[$DATE] HEARTBEAT已更新 | Gitea:$GITEA_STATUS | Gateway:$GATEWAY_STATUS | 会话:$ACTIVE_SESSIONS" >> "$LOG_FILE"
# 保留最近1000行日志
tail -n 1000 "$LOG_FILE" > "$LOG_FILE.tmp" && mv "$LOG_FILE.tmp" "$LOG_FILE"
}
# 执行更新
update_heartbeat