fix: reject noncanonical cursors and verify storage failover
This commit is contained in:
+26
-5
@@ -1,19 +1,40 @@
|
||||
"""Map a process alias to its real container, then leave exactly it stopped."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
wanted = os.environ["TARGET_INSTANCE_ID"]
|
||||
ids = subprocess.check_output(["docker", "compose", "ps", "-q", "api"], text=True).split()
|
||||
for cid in ids:
|
||||
result = subprocess.run(
|
||||
["docker", "exec", cid, "python", "-c",
|
||||
"import urllib.request; r=urllib.request.urlopen('http://127.0.0.1:8080/health/live'); print(r.headers['X-Instance-Id'])"],
|
||||
text=True, capture_output=True, check=False,
|
||||
[
|
||||
"docker",
|
||||
"exec",
|
||||
cid,
|
||||
"python",
|
||||
"-c",
|
||||
"import urllib.request; r=urllib.request.urlopen('http://127.0.0.1:8080/health/live'); print(r.headers['X-Instance-Id'])",
|
||||
],
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip() == wanted:
|
||||
subprocess.run(["docker", "stop", "--time", "8", cid], check=True, stdout=subprocess.DEVNULL)
|
||||
print(json.dumps({"stopped_container": cid, "instance_id": wanted}))
|
||||
subprocess.run(
|
||||
["docker", "stop", "--time", "8", cid], check=True, stdout=subprocess.DEVNULL
|
||||
)
|
||||
record = {
|
||||
"stopped_container": cid,
|
||||
"instance_id": wanted,
|
||||
"stopped_at": datetime.now(UTC).isoformat(),
|
||||
}
|
||||
Path("evidence").mkdir(exist_ok=True)
|
||||
with Path("evidence/failover-hooks.jsonl").open("a") as output:
|
||||
output.write(json.dumps(record) + "\n")
|
||||
print(json.dumps(record))
|
||||
break
|
||||
else:
|
||||
raise SystemExit("Target instance not found among this project's API containers")
|
||||
|
||||
Reference in New Issue
Block a user