Collect Ubuntu Livepatch status in the agent
CI / tests (Python 3.10) (pull_request) Successful in 22s
CI / tests (Python 3.11) (pull_request) Successful in 22s
CI / tests (Python 3.12) (pull_request) Successful in 21s
CI / tests (Python 3.13) (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 2s
CI / tests (Python 3.10) (pull_request) Successful in 22s
CI / tests (Python 3.11) (pull_request) Successful in 22s
CI / tests (Python 3.12) (pull_request) Successful in 21s
CI / tests (Python 3.13) (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 2s
kernelwatch-livepatch.service runs canonical-livepatch as root with no network and a read-only filesystem, and a small python3 helper keeps the running kernel's state, check state, support, end-of-support date and fix count in /run/kernelwatch/livepatch. The agent (0.4.0) reads that file the way it reads needrestart's and never runs the snap itself. NoNewPrivileges=yes can't be used: snap-confine fails under it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fa86de11f
commit
b59336d7e2
11 files changed
+273
-8
No files matched your search
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/python3 -I
|
||||
"""Flatten `canonical-livepatch status --format json` (stdin) into KEY: value lines (stdout).
|
||||
|
||||
Run as root by kernelwatch-livepatch.service, whose output kernelwatch-agent reads
|
||||
without needing the Livepatch snap or a shell JSON parser. Only the running
|
||||
kernel's entry is used. Exits 1, printing nothing, if the input isn't Livepatch
|
||||
status for a running kernel (Livepatch not enabled, or an error message)."""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def clean(value):
|
||||
return " ".join(str(value).split())[:64]
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
entry = next(e for e in data["Status"] if e.get("Running"))
|
||||
except (ValueError, KeyError, TypeError, StopIteration, AttributeError):
|
||||
return 1
|
||||
livepatch = entry.get("Livepatch") or {}
|
||||
fixes = [f for f in livepatch.get("Fixes") or [] if isinstance(f, dict) and f.get("Patched")]
|
||||
for key, value in (
|
||||
("STATE", livepatch.get("State")),
|
||||
("CHECK", livepatch.get("CheckState")),
|
||||
("SUPPORTED", entry.get("Supported")),
|
||||
("UPGRADE-REQUIRED", entry.get("UpgradeRequiredDate")),
|
||||
("FIXES", len(fixes)),
|
||||
):
|
||||
if value is not None:
|
||||
print(f"LIVEPATCH-{key}: {clean(value)}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user