workbuddy.xpcool.com/.workbuddy/tmp/kuma-bark-check.sh
夏犀麟 621acf12ef docs: xpcool.com 改版为随机壁纸站,同步索引/部署手册/日志
- MEMORY.md 索引:xpcool.com 的描述由「主域名(品牌首页)」改为
  「随机壁纸站(浏览器实时生成,可导出 4K;中英日韩 + 日夜主题)」。
- DEPLOY.md 站点表:同步 xpcool.com 一行的定位与产物体积,
  并记上部署脚本改为 pack-xpcool.ps1 + deploy-xpcool.ps1 两步走。
- 2026-09-14 日志:追加本次改版的完整记录,含三处根因分析
  (画面和泥、strata 层交叉、遮罩浓度过激)与两处真 bug。

顺带记录本次部署踩到的两个坑(已修进脚本,值得复用):
1. 新写的 .ps1 必须带 UTF-8 BOM,否则本机 PowerShell 5.1 按 GBK 解码,
   中文被截断导致解析失败 —— 用字节级前置 EF BB BF 修,不能用
   Get-Content -Raw + Out-File(会不可逆地破坏中文)。
2. deploy-xpcool.ps1 在 $ErrorActionPreference='Stop' 下,ssh 回传的
   nginx -t / openssl 正常输出走 stderr,被 PowerShell 当成终止性错误抛出,
   于是「远端其实跑通了、本地却中途退出」,表现为配置已装但没 reload 的
   半个部署。原生调用前后临时切回 Continue,成败只认 $LASTEXITCODE。
2026-09-14 01:01:32 +08:00

52 lines
2.3 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
# ============================================================
# Uptime Kuma → Bark 通知链路自检
# 做法:插一个必然失败的临时监控(指向 127.0.0.1:9
# 关联 Bark 通知id=1重启 Kuma 等它 DOWN 并推送,
# 再从 Bark 容器日志确认真的收到;最后清理临时监控。
# 注意:全程不清真站点。
# ============================================================
DB=/app/data/kuma.db
Q() { sudo -n docker exec uptime-kuma sqlite3 "$DB" "$1"; }
NAME='自检 · 临时Bark验证'
echo "=== 0) BACKUP ==="
sudo -n cp /data/uptime-kuma/kuma.db "/tmp/kuma.db.backup.$(date +%Y%m%d%H%M%S)"
echo "backup -> /tmp/kuma.db.backup.$(date +%Y%m%d%H%M%S)"
echo "=== 1) CLEAN PREVIOUS ==="
Q "DELETE FROM monitor_notification WHERE monitor_id IN (SELECT id FROM monitor WHERE name='$NAME');"
Q "DELETE FROM heartbeat WHERE monitor_id IN (SELECT id FROM monitor WHERE name='$NAME');"
Q "DELETE FROM monitor WHERE name='$NAME';"
echo "=== 2) INSERT TEMP MONITOR ==="
Q "INSERT INTO monitor (name,active,user_id,type,url,interval,retry_interval,maxretries,weight,accepted_statuscodes_json) VALUES ('$NAME',1,1,'http','http://127.0.0.1:9/',20,20,0,9999,'[\"200-399\"]');"
TMPID=$(Q "SELECT id FROM monitor WHERE name='$NAME' LIMIT 1;")
echo "tmp monitor id = [$TMPID]"
Q "INSERT INTO monitor_notification (monitor_id,notification_id) VALUES ($TMPID,1);"
echo "linked to notification 1"
Q "SELECT mn.monitor_id, mn.notification_id, n.name, json_extract(n.config,'\$.type') FROM monitor_notification mn JOIN notification n ON n.id=mn.notification_id WHERE mn.monitor_id=$TMPID;"
echo "=== 3) RESTART KUMA & WAIT ==="
sudo -n docker restart uptime-kuma >/dev/null 2>&1
sleep 80
echo "=== 4) BARK LOG (tail 12) ==="
sudo -n docker logs --tail 12 bark 2>&1
echo "=== 5) KUMA LOG notif ==="
sudo -n docker logs --tail 150 uptime-kuma 2>&1 | grep -iE "notif|bark|down" | tail -12
echo "=== 6) CLEANUP ==="
Q "DELETE FROM heartbeat WHERE monitor_id=$TMPID;"
Q "DELETE FROM monitor_notification WHERE monitor_id=$TMPID;"
Q "DELETE FROM monitor WHERE id=$TMPID;"
echo "cleanup rows done"
sudo -n docker restart uptime-kuma >/dev/null 2>&1
echo "kuma restarted"
echo "=== 7) FINAL STATE ==="
Q "SELECT id,name,active FROM monitor ORDER BY id;"
Q "SELECT COUNT(*) AS links FROM monitor_notification;"
echo "DONE"