38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
||
"""HEL-919 · 专属新实例启动守卫(脱敏模板;零网络、零真实调用)。
|
||
|
||
进程启动前拒绝一切未授权启动(ExecStartPre / instance_ctl.sh start 均调用):
|
||
- `window-active` 标记文件不存在 → 拒绝(默认关闭,不是获批窗口不开门);
|
||
- window.json 缺失/损坏、instance 不是 hel919、approved 不为真 → 拒绝;
|
||
- 当前时间 ≥ deadline_epoch → 拒绝(过期窗口重启不放行:期限持久在
|
||
window.json,进程重启不重置;新用量由库内 PersistentBudget 持久计数,
|
||
重启同样不重置、不新增)。
|
||
运行中到达截止由 expiry watch(instance_ctl.sh watch)有界收尾:停本实例
|
||
进程后不存在可出站进程,满足「到期拒绝新出站」;本守卫保证此后无法重启。
|
||
|
||
用法: python3 window_guard_hel919.py <base 目录>
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import sys
|
||
import time
|
||
from pathlib import Path
|
||
|
||
base = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
||
if base is None:
|
||
raise SystemExit("usage: window_guard_hel919.py <base>")
|
||
if not (base / "window-active").is_file():
|
||
raise SystemExit("hel919 window inactive: default closed")
|
||
wp = base / "window.json"
|
||
try:
|
||
w = json.loads(wp.read_text())
|
||
except Exception as exc:
|
||
raise SystemExit(f"hel919 window unreadable: {exc}") from exc
|
||
if w.get("instance") != "hel919":
|
||
raise SystemExit("hel919 window: wrong instance")
|
||
if not w.get("approved"):
|
||
raise SystemExit("hel919 window not approved")
|
||
if time.time() >= int(w["deadline_epoch"]):
|
||
raise SystemExit(f"hel919 window expired at {w.get('deadline_at')}")
|