20261112 完成#187真实序列录制回放与七指标评估

This commit is contained in:
2026-11-12 15:14:06 +08:00
parent 05650b23bf
commit dcf3e5b6ae
49 changed files with 6943 additions and 111 deletions

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""Run HTTP(S) and origin-separated read-only rsync daemons in the server namespace."""
import argparse
from pathlib import Path
import signal
import subprocess
import sys
import threading
from common import file_sha256, read_json
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--manifest", type=Path, required=True)
parser.add_argument("--log", type=Path, required=True)
parser.add_argument("--ready", type=Path, required=True)
args = parser.parse_args()
if args.ready.exists():
raise ValueError("stale/live readiness file exists; inspect the old server first")
manifest = read_json(args.manifest)
command = [sys.executable, str(Path(__file__).with_name("serve.py")), "--archive", manifest["archive"],
"--epoch", manifest["epoch_path"], "--bind", "0.0.0.0", "--cert", manifest["tls"]["cert"],
"--key", manifest["tls"]["key"], "--log", str(args.log), "--ready", str(args.ready)]
if manifest.get("scope_path"):
if file_sha256(Path(manifest["scope_path"])) != manifest["scope_sha256"]:
raise ValueError("replay scope changed since asset preparation")
command += ["--scope", manifest["scope_path"]]
for scheme in ("http", "https"):
for port in manifest[scheme + "_ports"]:
command += ["--" + scheme + "-port", str(port)]
children = []
stopped = threading.Event()
signal.signal(signal.SIGTERM, lambda *_: stopped.set())
signal.signal(signal.SIGINT, lambda *_: stopped.set())
try:
for config in manifest["rsync_configs"]:
children.append(subprocess.Popen(["rsync", "--daemon", "--no-detach", "--config", config]))
children.append(subprocess.Popen(command))
while not stopped.wait(0.2):
if any(child.poll() is not None for child in children):
raise RuntimeError("a replay child exited unexpectedly")
finally:
for child in reversed(children):
if child.poll() is None:
child.terminate()
for child in children:
try:
child.wait(timeout=10)
except subprocess.TimeoutExpired:
child.kill()
child.wait(timeout=5)
args.ready.unlink(missing_ok=True)
if __name__ == "__main__":
main()