fix(chv): 阶段 2 syncd 改走 systemd RuntimeDirectory=/run/chv-syncd

tmpfiles 行 d /run/chv/syncd 0755 chv chv 没用:tmpfiles-setup
跑在 cloud-init 建 chv 用户之前,属主解析失败整行被跳过,
客内 /run/chv/syncd 根本不存在(2026-11-07 真机实测:镜像
里有这行、目录没有,syncd 反复退出、restart counter 57)。
改走单元 RuntimeDirectory=chv-syncd(服务启动时由 systemd
按服务用户建目录,不依赖启动时序);状态写失败改为记日志
不杀进程;daemon 与驱动的 syncd 路径同步改到
/run/chv-syncd/。
This commit is contained in:
host committed 2026-11-08 09:45:00 +00:00
1 parent 8013431f63
commit 42b295fc71
4 files changed
+38 -18

No files matched your search

+17 -4
View File
@@ -30,8 +30,14 @@ import sys
import threading
import time
SYNC_SOCK = "/run/chv/syncd/syncd.sock"
STATUS_PATH = "/run/chv/syncd/sync-status.json"
# systemd RuntimeDirectory(见 build.sh 的 syncd 单元):服务启动
# 时由 systemd 按服务用户(chv)建 /run/chv-syncd,启动时序
# 不依赖 cloud-init 先建好 chv 用户。不要放回 /run/chv/ 下——
# tmpfiles-setup 跑在 cloud-init 建 chv 用户之前,带 chv 属主
# 的 tmpfiles 行会被跳过(2026-11-07 真机实测:目录根本没建,
# syncd 反复退出、长期 activating)。
SYNC_SOCK = "/run/chv-syncd/syncd.sock"
STATUS_PATH = "/run/chv-syncd/sync-status.json"
WORKSPACE = "/home/chv/workspace"
SYNC_BIN = "/usr/local/bin/chv-sync"
DEFAULT_INTERVAL = 300.0
@@ -116,8 +122,15 @@ class Syncd:
"consecutive_errors": 0, "cycles": 0}
def _write_status(self):
_atomic_write(self.status_path,
(json.dumps(self._status) + "\n").encode())
try:
_atomic_write(self.status_path,
(json.dumps(self._status) + "\n").encode())
except OSError as exc:
# 状态文件是可观测性,不是同步本身:写失败记一
# 行日志、不杀进程(2026-11-07 真机教训:写失败
# 抛到主线程致 syncd 反复退出、长期 activating)。
print("chv-syncd: status write failed: %s" % exc,
file=sys.stderr, flush=True)
def run_cycle(self):
"""一轮同步:先 pull 再 push;任一步失败即停住记 error。"""