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

+12 -4
View File
@@ -7,6 +7,7 @@
# agent/deploy.sh --register new01 register on the dashboard, then install
# agent/deploy.sh --rotate web01 issue a new token, then reinstall
# agent/deploy.sh --dry-run show what would happen
# agent/deploy.sh -- --with-needrestart pass the rest to install.sh
#
# Settings: agent/deploy.conf (see deploy.conf.example). Hosts: agent/hosts,
# one per line: `<ssh target> [kernelwatch name]`; the name defaults to the
@@ -17,7 +18,8 @@ set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
CONF=${KERNELWATCH_DEPLOY_CONF:-$here/deploy.conf}
HOSTS_FILE=${KERNELWATCH_HOSTS:-$here/hosts}
FILES=(kernelwatch-agent kernelwatch-agent.service kernelwatch-agent.timer install.sh)
FILES=(kernelwatch-agent kernelwatch-agent.service kernelwatch-agent.timer
kernelwatch-needrestart.service install.sh)
NAME_RE='^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$'
SERVER_URL=
@@ -97,7 +99,7 @@ deploy_one() {
if ((dry_run)); then
if [[ $mode == upgrade ]]; then
echo " copy agent to $target, run install.sh (keeps config and token)" >&2
echo " copy agent to $target, run install.sh ${install_args[*]} (keeps config and token)" >&2
else
echo " on $DASHBOARD: kernelwatch ${mode/register/add-host} ${name:-<its hostname -s>}" >&2
echo " copy agent and token to $target, run install.sh --server $SERVER_URL" >&2
@@ -120,7 +122,7 @@ deploy_one() {
return 1
fi
local -a install=(sudo "$dir/install.sh")
local -a install=(sudo "$dir/install.sh" "${install_args[@]}")
if [[ $mode != upgrade ]]; then
# 2. Get a token from the dashboard and hand it over on stdin, never argv.
say " $mode $name on $DASHBOARD"
@@ -143,13 +145,19 @@ deploy_one() {
fi
}
usage() { sed -n '2,15s/^# \{0,1\}//p' "$0"; }
usage() { sed -n '2,16s/^# \{0,1\}//p' "$0"; }
mode=upgrade
dry_run=0
targets=()
install_args=()
while (($#)); do
case $1 in
--)
shift
install_args=("$@")
break
;;
--register) mode=register ;;
--rotate) mode=rotate ;;
--dry-run) dry_run=1 ;;