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:
1 parent
69d4cf6363
commit
834c1459c0
14 files changed
+258
-26
No files matched your search
@@ -13,6 +13,7 @@ import re
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from . import AGENT_VERSION
|
||||
from .config import Config
|
||||
|
||||
LEVELS = ("stale", "reboot", "update", "ok")
|
||||
@@ -34,6 +35,10 @@ class Status:
|
||||
self.level = level
|
||||
self.reasons.append(reason)
|
||||
|
||||
def note(self, reason: str) -> None:
|
||||
"""A reason worth showing that doesn't change the level."""
|
||||
self.reasons.append(reason)
|
||||
|
||||
@property
|
||||
def rank(self) -> int:
|
||||
return _RANK[self.level]
|
||||
@@ -93,6 +98,14 @@ def kernel_reboot_pending(report: dict[str, Any]) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _version_tuple(v: str) -> tuple[int, ...]:
|
||||
return tuple(int(p) if p.isdigit() else 0 for p in v.split("."))
|
||||
|
||||
|
||||
def agent_outdated(version: str | None) -> bool:
|
||||
return bool(version) and _version_tuple(version) < _version_tuple(AGENT_VERSION)
|
||||
|
||||
|
||||
def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
|
||||
cfg: Config) -> Status:
|
||||
status = Status()
|
||||
@@ -116,10 +129,21 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
|
||||
if sec := report.get("security_count"):
|
||||
status.raise_to("update", f"{sec} security update{'s' if sec != 1 else ''} pending")
|
||||
|
||||
if services := report.get("services_need_restart"):
|
||||
shown = ", ".join(s.removesuffix(".service") for s in services[:5])
|
||||
more = f", +{len(services) - 5} more" if len(services) > 5 else ""
|
||||
n = len(services)
|
||||
status.raise_to("update", f"{n} service{'s' if n != 1 else ''} need{'' if n != 1 else 's'} "
|
||||
f"restart: {shown}{more}")
|
||||
|
||||
apt_age = report.get("apt_lists_age_seconds")
|
||||
if apt_age is None:
|
||||
status.raise_to("update", "package list age unknown")
|
||||
elif apt_age / 3600 > cfg.apt_stale_after_hours:
|
||||
status.raise_to("update", f"package lists {apt_age / 86400:.0f}d old; apt update not running?")
|
||||
|
||||
if agent_outdated(report.get("agent_version")):
|
||||
status.note(f"agent {report['agent_version']} is older than {AGENT_VERSION}; "
|
||||
"run agent/deploy.sh")
|
||||
|
||||
return status
|
||||
Reference in new issue
Block a user