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
+21
-2
@@ -2,6 +2,11 @@
|
||||
# Install or upgrade kernelwatch-agent on a Debian 12/13 or Ubuntu 22.04/24.04 host.
|
||||
#
|
||||
# sudo ./install.sh --server https://kernelwatch.example.internal [--ca ca.pem]
|
||||
# [--with-needrestart]
|
||||
#
|
||||
# --with-needrestart installs needrestart (Ubuntu has it already) so the
|
||||
# dashboard can show services needing a restart, and sets it to only list
|
||||
# services after apt upgrades instead of asking interactively.
|
||||
#
|
||||
# The host token (from `kernelwatch add-host <name>` on the server) is read
|
||||
# from --token-file, the KERNELWATCH_TOKEN environment variable, or a prompt,
|
||||
@@ -13,13 +18,15 @@ here=$(cd "$(dirname "$0")" && pwd)
|
||||
server=
|
||||
ca=
|
||||
token_file=
|
||||
with_needrestart=0
|
||||
|
||||
while (($#)); do
|
||||
case $1 in
|
||||
--server) server=${2:?--server needs a URL}; shift 2 ;;
|
||||
--ca) ca=${2:?--ca needs a file}; shift 2 ;;
|
||||
--token-file) token_file=${2:?--token-file needs a file}; shift 2 ;;
|
||||
-h | --help) sed -n '2,9s/^# \{0,1\}//p' "$0"; exit 0 ;;
|
||||
--with-needrestart) with_needrestart=1; shift ;;
|
||||
-h | --help) sed -n '2,14s/^# \{0,1\}//p' "$0"; exit 0 ;;
|
||||
*) echo "unknown argument: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
@@ -36,10 +43,22 @@ esac
|
||||
if ! command -v curl >/dev/null; then
|
||||
apt-get install -y --no-install-recommends curl ca-certificates
|
||||
fi
|
||||
if ((with_needrestart)); then
|
||||
if [[ ! -x /usr/sbin/needrestart ]]; then
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends needrestart
|
||||
fi
|
||||
install -d -m 0755 /etc/needrestart/conf.d
|
||||
cat >/etc/needrestart/conf.d/kernelwatch.conf <<'NRCONF'
|
||||
# Installed by kernelwatch: after apt upgrades, list services that need a
|
||||
# restart instead of asking. Delete this file to restore the default.
|
||||
$nrconf{restart} = 'l';
|
||||
NRCONF
|
||||
fi
|
||||
|
||||
install -d -m 0755 /etc/kernelwatch
|
||||
install -m 0755 "$here/kernelwatch-agent" /usr/local/sbin/kernelwatch-agent
|
||||
install -m 0644 "$here/kernelwatch-agent.service" "$here/kernelwatch-agent.timer" /etc/systemd/system/
|
||||
install -m 0644 "$here/kernelwatch-agent.service" "$here/kernelwatch-agent.timer" \
|
||||
"$here/kernelwatch-needrestart.service" /etc/systemd/system/
|
||||
|
||||
if [[ -n $ca ]]; then
|
||||
install -m 0644 "$ca" /etc/kernelwatch/ca.pem
|
||||
|
||||
Reference in new issue
Block a user