Report services needing a restart via a separate root needrestart unit

needrestart has to inspect every process, which an unprivileged agent
can't (and unprivileged it gave false kernel results). Add
kernelwatch-needrestart.service: root with only CAP_SYS_PTRACE and
CAP_DAC_READ_SEARCH, PrivateNetwork=yes, list-only (-r l). It writes
`needrestart -b` output to /run/kernelwatch/needrestart; the agent unit
pulls it in before each report and reads the file (ignored if older than
2h). The agent no longer runs needrestart itself. Skipped cleanly when
needrestart isn't installed: the dashboard shows "?" and status is
unaffected.

Server: services_need_restart / sessions_need_restart fields, an
"update"-level reason, a Services column, and a note (not an escalation)
for hosts running an agent older than the one shipped with the server.

install.sh --with-needrestart installs needrestart and sets it to list
services after apt upgrades instead of prompting; deploy.sh passes
anything after `--` to install.sh. Agent 0.2.0, server 0.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 11:54:39 -04:00
1 parent 69d4cf6363
commit 834c1459c0
14 files changed
+258 -26

No files matched your search

+15 -1
View File
@@ -84,6 +84,16 @@ def utc(ts: float | None) -> str:
return time.strftime("%Y-%m-%d %H:%M:%S UTC", time.gmtime(ts)) if ts else ""
def services_summary(report: dict[str, Any]) -> tuple[str, str]:
"""(short cell text, full description) for services needing a restart."""
services = report.get("services_need_restart")
if services is None:
return "?", "unknown: needrestart not installed (install.sh --with-needrestart)"
if not services:
return "0", "none"
return str(len(services)), ", ".join(services)
def badge(level: str) -> str:
return f'<span class="badge {e(level)}">{e(level)}</span>'
@@ -397,7 +407,7 @@ class Handler(BaseHTTPRequestHandler):
if not hosts else
'<div class="table-wrap"><table><thead><tr>'
"<th>Status</th><th>Host</th><th>OS</th><th>Running kernel</th>"
"<th>Newest installed</th><th>Updates</th><th>Uptime</th><th>Last seen</th>"
"<th>Newest installed</th><th>Updates</th><th>Services</th><th>Uptime</th><th>Last seen</th>"
"<th>Details</th></tr></thead><tbody>" + "".join(rows) + "</tbody></table></div>"
)
body = f'<main><div class="summary">{summary}</div>{table}</main>'
@@ -411,6 +421,7 @@ class Handler(BaseHTTPRequestHandler):
sec = r.get("security_count")
total = r.get("upgradable_count")
updates = "–" if total is None else f"{total}" + (f" ({sec} sec)" if sec else "")
services = services_summary(r)
return (
"<tr>"
f"<td>{badge(status.level)}</td>"
@@ -419,6 +430,7 @@ class Handler(BaseHTTPRequestHandler):
f"<td><code>{e(r.get('kernel_running') or '–')}</code></td>"
f"<td><code>{e(r.get('kernel_newest_installed') or '–')}</code></td>"
f"<td>{e(updates)}</td>"
f'<td title="{e(services[1])}">{e(services[0])}</td>'
f"<td>{e(duration(r.get('uptime_seconds')))}</td>"
f'<td title="{e(utc(h["received_at"]))}">{e(ago(h["received_at"], now))}</td>'
f'<td class="reasons">{"<br>".join(e(x) for x in status.reasons) or "–"}</td>'
@@ -469,6 +481,8 @@ class Handler(BaseHTTPRequestHandler):
field("Updates pending", r.get("upgradable_count")),
field("Security updates", r.get("security_count")),
field("Reboot-required packages", r.get("reboot_required_pkgs"), code=True),
field("Services needing restart", services_summary(r)[1]),
field("Sessions needing restart", r.get("sessions_need_restart")),
field("Package lists age", duration(r.get("apt_lists_age_seconds"))
if r.get("apt_lists_age_seconds") is not None else None),
field("Uptime", duration(r.get("uptime_seconds")) if r.get("uptime_seconds") is not None else None),