fix(deploy): health_monitor flock 失败计数回传

flock 子 shell 递增后未回传 FAIL,导致 Layer 3 永不触发重启与 Telegram。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Agent
2026-06-07 20:53:14 +08:00
parent b8785d1d51
commit 764703d401
4 changed files with 33 additions and 1 deletions
+10
View File
@@ -426,3 +426,13 @@
{"ts":"2026-06-07T20:17:03+08:00","date":"2026-06-07","gate":"shell_eol","result":"PASS","detail":"all tracked sh LF"}
{"ts":"2026-06-07T20:17:03+08:00","date":"2026-06-07","gate":"text_eol","result":"PASS","detail":"git index LF"}
{"ts":"2026-06-07T20:17:03+08:00","date":"2026-06-07","gate":"summary","result":"PASS","detail":"7/7"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"changelog","result":"PASS","detail":"2026-06-07-health-monitor-flock-fail-count-fix.md 21lines"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"audit","result":"PASS","detail":"2026-06-07-ops-patrol-layer3-telegram.md"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"test","result":"PASS","detail":"all passed"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"lint","result":"PASS","detail":"0 violations"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"import","result":"PASS","detail":"ok"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"security","result":"PASS","detail":"0 HIGH"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"review","result":"PASS","detail":"audit covers changes"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"shell_eol","result":"PASS","detail":"all tracked sh LF"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"text_eol","result":"PASS","detail":"git index LF"}
{"ts":"2026-06-07T20:53:00+08:00","date":"2026-06-07","gate":"summary","result":"PASS","detail":"7/7"}
+1
View File
@@ -106,6 +106,7 @@ bump_fail_count() {
fail=$((fail + 1))
echo "$fail" > "$FAIL_FILE"
) 9>"${FAIL_FILE}.lock"
fail="$(cat "$FAIL_FILE" 2>/dev/null || echo 0)"
else
fail="$(cat "$FAIL_FILE" 2>/dev/null || echo 0)"
fail=$((fail + 1))
@@ -7,7 +7,7 @@
| `server/infrastructure/env_file.py` | `.env` upsert/readUTF-8 LF |
| `server/application/services/ops_patrol_sync.py` | Telegram → `/app/.env`、persist 卷、host `.env.prod` |
| `server/api/settings.py` | `set_setting` 钩子;`GET/POST ops-patrol/*` |
| `deploy/health_monitor.sh` | `load_telegram_from_db` MySQL 回退 |
| `deploy/health_monitor.sh` | `load_telegram_from_db` + `bump_fail_count` flock 修复 |
| `deploy/deploy-production.sh` | 部署成功自动 `install_ops_cron.sh` |
| `deploy/nexus-1panel.sh` | `sync_env_prod_to_volume` 含 Telegram 键 |
| `frontend/src/pages/SettingsPage.vue` | Layer 3 巡检状态与同步 UI |
@@ -0,0 +1,21 @@
# Changelog — health_monitor flock 失败计数修复
**日期**: 2026-06-07
## 摘要
修复 `bump_fail_count` 在使用 `flock` 时子 shell 未回传计数、导致 `FAIL` 恒为 0、Layer 3 永不触发重启/Telegram 的 bug。
## 动机
生产模拟巡检时发现连续 3 次 /health 失败后 `last_restart` 仍为空;`bash -x` 显示 `FAIL=0``/tmp/nexus_health_fail_count` 已为 3。
## 涉及文件
- `deploy/health_monitor.sh`
## 验证
```bash
# 阻断 127.0.0.1:8600 后连续执行 3 次 health_monitor.sh,第 3 次应触发 Telegram + docker restart
```