Files
codex-app-server/chv-guest/chv-gitea-worker.service
T
host e31354dc58 fix(chv-muse-r12fix3-1): worker 开机时序竞态:Condition + path 触发,不赌重启预算(P6 缺口 ①)
R12 复测 2 钉死:剩下的 226 只点名 /home/chv/workspace——工作区由
cloud-final 的 chv-sync boot 克隆出来,晚于 multi-user.target 约
9 秒,worker 的 5 次启动预算在工作区出现前耗尽(5 台 VM 2 台
failed,手工 reset-failed + start 后立即 active,二进制无辜)。

修法三选一,选 (a)——让服务根本不在工作区出现前启动:
新单元 chv-gitea-worker.path(PathExists=/home/chv/workspace,
工作区一出现即触发启动)+ 服务加
ConditionPathExists=/home/chv/workspace(开机那次启动在命名空间
搭建之前干净跳过,不 226、不耗重启预算)。两者缺一不可:
Condition 本身绝不重试,没有 .path 它就是一次跳过、服务永远不
起;只有 .path 而无 Condition,开机那次启动仍会在命名空间搭建
时 226 撞上限速。WantedBy=multi-user.target 保留(is-enabled 仍
为 enabled),runcmd 只启动 .path 单元(cloud-final 时工作区尚
未 clone,直接 start 服务会 226);.path 进 buildinfo contents
与两处 lockfile 登记,P6 预检由三件扩为四件。

不用 (b) 放宽 StartLimit:放宽只是把竞态窗口拉大,wake 时间在
负载下已翻倍(R12 复测 2),预算仍可能耗尽,仍是时序赌博。
不用 (c) 把工作区创建提前到 tmpfiles-setup 之前:/home/chv 本身
07:23:40 才出现(cloud-init 建 chv 用户),晚于 tmpfiles-setup
(07:23:24);硬约束:绝不盲目补 tmpfiles 行。ExecStartPre 也不
行——命名空间搭建在它之前,救不了 226。

测试:WorkerUnitBootRaceTest 新增 8 项——Condition 在位、
StartLimit 未放宽(修法语义钉)、.path 触发配对(PathExists +
WantedBy、无 Unit= 覆盖)、服务 WantedBy 保留、build.sh 启用
.path + runcmd 只起 .path、绝无工作区 tmpfiles 行、buildinfo 与
lockfile 登记;BuildInfoContentsTest 的 P6 件加 .path;P2/P4 干
跑夹具一并拷入 .path。P6/P2/P4 三模块 174 项全过。
2026-11-08 09:45:48 +00:00

56 lines
3.0 KiB
Desktop File
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.
[Unit]
Description=CHV Gitea sync privsep worker (feat-chv-muse-p6)
After=network-online.target chv-authd.service
Wants=network-online.target
# authd 是可选依赖:worker 的 git 经 P3 helper 向 authd 取凭证;
# authd 没起来时 worker 的 git 调用直接拒绝,不静默用旧凭证。
# 开机时序(round-12 修复轮第三轮,缺口 ①):工作区
# /home/chv/workspace 由 cloud-final 的 chv-sync boot 克隆出来,
# 晚于 multi-user.target 约 9 秒;而 ReadWritePaths 的路径必须在
# systemd 建 mount namespace 时已存在,否则 226/NAMESPACE。
# ConditionPathExists 让开机那次启动在工作区出现前干净跳过
# (不耗重启预算、不 226);真正拉起靠 chv-gitea-worker.path
# (工作区一出现即触发启动)。Condition 本身绝不重试——没有
# .path 单元它就是一次跳过、服务永远不起;反过来只有 .path 而
# 无 Condition,开机那次启动仍会在命名空间搭建时 226 撞上限速。
# 两者缺一不可。StartLimit 不放宽:放宽只是把竞态窗口拉大,
# wake 时间在负载下已翻倍(R12 复测 2),预算仍可能耗尽;
# tmpfiles.d 也不补工作区行:/home/chv 本身 07:23:40 才出现,
# 晚于 tmpfiles-setup(07:23:24),补了也没用。
ConditionPathExists=/home/chv/workspace
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/chv-gitea-worker
Restart=on-failure
RestartSec=2
# systemd 沙箱(与 P3 authd 同款 root 单元外服务口径,再收紧):
# 只读系统、独立 /tmp、不许提权、不留 capability、只许 Unix 与
# inet 协议族、只许 @system-service 系统调用、读写路径只限工作区
# 与 worker 运行时目录。网络层强制(eBPF)是 P5 的范围,不在这里
# 冒充——出口收紧靠 Sentinel 评估(authd 放凭证前)+ 只配 helper
# 的 git(见 chv-gitea-worker.py)。
ProtectSystem=strict
PrivateTmp=yes
NoNewPrivileges=yes
CapabilityBoundingSet=
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
SystemCallFilter=@system-service
# ReadWritePaths 下的路径必须在开机时已存在(ProtectSystem=strict
# 下 systemd 建 mount namespace 的硬要求,缺一个即 226/NAMESPACE):
# /run/chv-gitea 与 /var/log/chv-gitea-worker.log 由
# /etc/tmpfiles.d/chv.conf 预建(build.sh 内联写,round-12 修复轮
# 第二轮项 1);/home/chv/workspace 由 ConditionPathExists +
# chv-gitea-worker.path 守门(round-12 修复轮第三轮缺口 ①,见
# [Unit];R12 复测 2 钉死它才是剩下的 226——开机时序竞态,不要
# 再写“开机时已在”)。ExecStartPre 不能替代 tmpfiles.d——命名空间
# 搭建在它之前,226 发生在它运行之前。
ReadWritePaths=/home/chv/workspace /run/chv-gitea /var/log/chv-gitea-worker.log
# worker 崩溃不拖垮 agent:broker/薄 CLI 收到类型化失败即返回,
# 不重试、不挂起;systemd 只负责拉起 worker 本身。
[Install]
WantedBy=multi-user.target