ops(startup): startup-110.sh 加入 Step 7 Sentry 自動啟動
Sentry 已安裝於 /opt/sentry (2026-03-24),但重開機後未自動啟動 加入非阻塞啟動 + 重開機損壞修復邏輯: - sentry-postgres WAL 損壞 → pg_resetwal -f 自動修復 - sentry-redis dump.rdb 損壞 → 自動刪除重建 - 啟動後 20s 非阻塞健康驗證 根因: 2026-04-05 重開機後 PostgreSQL WAL + Redis RDB + ClickHouse parts 全部損壞 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,55 @@ else
|
||||
log "⚠️ 找不到 act-runner compose 檔案: $RUNNER_DIR/docker-compose.yml"
|
||||
fi
|
||||
|
||||
# ──────────────────────────────────────────────
|
||||
# STEP 7: Sentry(Error Tracking)
|
||||
# 2026-04-05 Claude Code: 加入 — 解決重開機後 Sentry 未自動啟動
|
||||
# 安裝位置: /opt/sentry (2026-03-24 已安裝)
|
||||
# DSN: awoooi-web :2, awoooi-api :3 (見 memory/project_sentry_full_integration.md)
|
||||
#
|
||||
# 已知重開機後損壞問題 (2026-04-05 事故記錄):
|
||||
# - sentry-postgres: WAL 損壞 → pg_resetwal -f
|
||||
# - sentry-redis: dump.rdb 損壞 → 刪除重建 (redis 是 session cache,可丟失)
|
||||
# - sentry-clickhouse: system table parts 損壞 → 刪除對應 store/ 目錄
|
||||
# ──────────────────────────────────────────────
|
||||
log "[7/7] 啟動 Sentry..."
|
||||
SENTRY_DIR="/opt/sentry"
|
||||
if [ -d "$SENTRY_DIR" ]; then
|
||||
cd "$SENTRY_DIR"
|
||||
|
||||
# 修復 Sentry PostgreSQL WAL (若損壞)
|
||||
SENTRY_PG_VOL="sentry-postgres"
|
||||
PG_RUNNING=$(docker ps --filter name=sentry-self-hosted-postgres-1 --format "{{.Status}}" 2>/dev/null | head -1)
|
||||
if echo "$PG_RUNNING" | grep -q "Restarting"; then
|
||||
log "⚠️ sentry-postgres 損壞,嘗試 pg_resetwal 修復..."
|
||||
docker run --rm -u 999 -v ${SENTRY_PG_VOL}:/var/lib/postgresql/data \
|
||||
postgres:14 pg_resetwal -f /var/lib/postgresql/data 2>&1 | head -3 || true
|
||||
log "✅ sentry-postgres WAL 修復完成"
|
||||
fi
|
||||
|
||||
# 修復 Sentry Redis (若 dump.rdb 損壞)
|
||||
REDIS_STATUS=$(docker inspect sentry-self-hosted-redis-1 --format='{{.State.Status}}' 2>/dev/null || echo "missing")
|
||||
if [ "$REDIS_STATUS" = "restarting" ]; then
|
||||
log "⚠️ sentry-redis 損壞,清除 dump.rdb..."
|
||||
docker run --rm --user root -v sentry-redis:/data alpine \
|
||||
sh -c 'rm -f /data/dump.rdb && echo cleared' 2>/dev/null || true
|
||||
log "✅ sentry-redis dump.rdb 已清除"
|
||||
fi
|
||||
|
||||
docker compose up -d 2>&1 | tail -5
|
||||
log "✅ Sentry 啟動指令已發送 (啟動約需 2-3 分鐘)"
|
||||
sleep 20
|
||||
# 非阻塞驗證:Sentry 啟動慢,只做快速健康檢查
|
||||
HTTP_CODE=$(curl -sf --max-time 10 -o /dev/null -w "%{http_code}" http://localhost:9000/ 2>/dev/null || echo "0")
|
||||
if echo "$HTTP_CODE" | grep -qE "^(200|302|400)$"; then
|
||||
log "✅ Sentry 已回應 (HTTP $HTTP_CODE)"
|
||||
else
|
||||
log "⚠️ Sentry 尚未就緒(正常現象,通常需 2-3 分鐘,HTTP=$HTTP_CODE)"
|
||||
fi
|
||||
else
|
||||
log "⚠️ 找不到 Sentry 目錄: $SENTRY_DIR"
|
||||
fi
|
||||
|
||||
# ──────────────────────────────────────────────
|
||||
# 完成
|
||||
# ──────────────────────────────────────────────
|
||||
@@ -184,5 +233,6 @@ log "Gitea: http://192.168.0.110:3001"
|
||||
log "Grafana: http://192.168.0.110:3002"
|
||||
log "Alertmanager: http://192.168.0.110:9093"
|
||||
log "Gitea Runner: docker logs gitea-runner"
|
||||
log "Sentry: http://192.168.0.110:9000"
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user