Collect authorized daemon logs before failed Core VM cleanup

This commit is contained in:
Pavel Isaev 2026-11-08 07:58:18 +03:00
parent 35b7cb9b6e
commit 1ee9d9aaac

View file

@ -91,6 +91,28 @@ def main():
results["checks"].append({"command": text, "exit_code": code})
event("command-result", command=text, exit_code=code)
if code:
# Preserve daemon diagnostics before the VM and disk are cleaned up.
# Use the authenticated CLI as root, just like the failed operation.
child.expect(r"(?:root|coretest)@[^\r\n]*[#$] ")
if privileged:
diagnostic = """archipelago transaction list; python3 - <<'PY'
import json, subprocess
p = subprocess.run(['archipelago', 'transaction', 'list'], capture_output=True, text=True)
if p.returncode == 0:
data = json.loads(p.stdout)
for record in data['transactions']:
identity = record.get('id') or record.get('Id')
if identity:
subprocess.run(['archipelago', 'transaction', 'log', identity], check=False)
PY
journalctl -u archipelagod.service -n 80 --no-pager
"""
try:
child.sendline("sudo /bin/bash -c " + shlex.quote(diagnostic) +
"; printf '\\n__ARCHIPELAGO_DIAGNOSTICS_DONE__\\n'")
child.expect(r"\r?\n__ARCHIPELAGO_DIAGNOSTICS_DONE__\r?\n", timeout=120)
except (pexpect.TIMEOUT, pexpect.EOF) as diagnostic_error:
event("diagnostics-incomplete", error=str(diagnostic_error))
raise RuntimeError(f"Guest command failed ({code}): {text}")
child.expect(r"(?:root|coretest)@[^\r\n]*[#$] ")