CI / tests (Python 3.10) (pull_request) Successful in 39s
CI / tests (Python 3.11) (pull_request) Successful in 38s
CI / tests (Python 3.12) (pull_request) Successful in 39s
CI / tests (Python 3.13) (pull_request) Successful in 38s
CI / lint (pull_request) Successful in 3s
kernelwatch flags pending reboots but never reboots anything. For hosts without Livepatch, add "Rebooting automatically" to the agents guide: enabling unattended-upgrades on Debian (its kernel hook is what creates /run/reboot-required there), a drop-in for Automatic-Reboot and Automatic-Reboot-Time, picking times before 05:00 so the reboot lands inside the 24h reboot alert window (apt-daily-upgrade runs 06:00-07:00), staggering dependent hosts and the dashboard host, and how each outcome shows up in kernelwatch: back to ok minutes after boot, stale if it doesn't come back, a reboot alert if it never happens. Also why to leave it off on Livepatch hosts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
248 lines
11 KiB
Markdown
248 lines
11 KiB
Markdown
# Agents
|
||
|
||
[← kernelwatch](../README.md)
|
||
|
||
Installing the agent on hosts, one at a time or across the whole fleet.
|
||
|
||
## Adding a host
|
||
|
||
On the server:
|
||
|
||
```sh
|
||
sudo kernelwatch add-host web01
|
||
# prints a token, shown once
|
||
```
|
||
|
||
On the host (copy the `agent/` directory over, or clone the repo):
|
||
|
||
```sh
|
||
sudo ./agent/install.sh --server https://kernelwatch.example.internal [--ca root.pem]
|
||
# paste the token when prompted
|
||
```
|
||
|
||
The installer puts the agent in `/usr/local/sbin`, writes `/etc/kernelwatch/agent.conf`
|
||
and `agent.token` (root, 0600), enables `kernelwatch-agent.timer` and sends a first
|
||
report. After that, the agent reports 2 minutes after boot and then hourly, with up
|
||
to 15 minutes of jitter.
|
||
|
||
For unattended installs, set `KERNELWATCH_TOKEN=...` instead of using the prompt.
|
||
|
||
Add `--with-needrestart` to also report services needing a restart (Debian
|
||
needs this; Ubuntu already has needrestart). It installs needrestart if
|
||
missing and sets it to *list* services after apt upgrades instead of asking
|
||
interactively. Delete `/etc/needrestart/conf.d/kernelwatch.conf` to undo that.
|
||
|
||
Add `--with-apt-update` to refresh apt's package lists before each report
|
||
(recommended on Debian, see "Fresh package lists" in [How it works](how-it-works.md)). It's the same as running `apt update`
|
||
hourly: lists only, nothing is installed. If apt is busy, the refresh is
|
||
skipped and the report goes ahead. `--without-apt-update` turns it off;
|
||
re-running the installer with neither keeps the current setting.
|
||
|
||
Useful on a host:
|
||
|
||
```sh
|
||
sudo kernelwatch-agent --print # see exactly what would be sent
|
||
sudo systemctl start kernelwatch-agent # report now
|
||
systemctl list-timers kernelwatch-agent.timer
|
||
journalctl -u kernelwatch-agent
|
||
```
|
||
|
||
## Ubuntu Livepatch
|
||
|
||
[Livepatch](https://ubuntu.com/security/livepatch) applies high and critical
|
||
kernel fixes without a reboot. kernelwatch needs no setup for it: the agent
|
||
always installs `kernelwatch-livepatch.service`, which runs only on hosts that
|
||
have the `canonical-livepatch` snap. Turn Livepatch on for the host and the next
|
||
report picks it up. What it changes on the dashboard is in
|
||
[How it works](how-it-works.md) under "Ubuntu Livepatch".
|
||
|
||
Livepatch is part of [Ubuntu Pro](https://ubuntu.com/pro), which is free for
|
||
personal use on up to five machines. Get your token from the
|
||
[Pro dashboard](https://ubuntu.com/pro/dashboard), then on the host:
|
||
|
||
```sh
|
||
sudo pro attach <token> # usually enables Livepatch and ESM too
|
||
sudo pro enable livepatch # no-op if attach already did
|
||
sudo canonical-livepatch status # check the kernel is supported and patches applied
|
||
```
|
||
|
||
Check that kernelwatch sees it:
|
||
|
||
```sh
|
||
sudo systemctl start kernelwatch-agent # runs kernelwatch-livepatch.service first
|
||
sudo cat /run/kernelwatch/livepatch # LIVEPATCH-STATE: applied (or nothing-to-apply)
|
||
```
|
||
|
||
The host page then shows a Livepatch row, such as "applied, 2 fixes applied,
|
||
supported until 2027-09-07". From then on:
|
||
|
||
- A newer kernel that's installed but not running, or a `/run/reboot-required`
|
||
caused only by `linux-*` packages, shows as a note ("live-patched; kernel
|
||
upgrade needed by ...") instead of putting the host in `reboot`. Other reboot
|
||
reasons (libc, systemd) still count.
|
||
- That cover ends 14 days before the running kernel's Livepatch support does,
|
||
and the host goes to `reboot` as usual.
|
||
- If Livepatch breaks, or a host that used to report it stops, you get an
|
||
[ntfy alert](alerts.md#stale-host-reboot-and-update-alerts-ntfy) after
|
||
`livepatch_alert_after_hours` (default 6).
|
||
|
||
Attaching to Pro also enables ESM (`esm-infra`), which the OS end-of-support
|
||
check counts: an Ubuntu release past standard support stays fine while ESM is
|
||
on. The host page's "OS security support" row shows it.
|
||
|
||
Things to know:
|
||
|
||
- **Supported kernels only.** Livepatch covers LTS releases on the kernel
|
||
flavours Canonical supports. On any other kernel, `canonical-livepatch status`
|
||
says it isn't supported, and kernelwatch shows "livepatch not healthy (...,
|
||
unsupported)" and gives no reboot cover.
|
||
- **Turning it off.** After `sudo pro disable livepatch` (or `pro detach`), the
|
||
host stops reporting Livepatch, which looks the same as a dead daemon: you get
|
||
one alert after `livepatch_alert_after_hours`, then nothing more. That's
|
||
expected.
|
||
- **Debian** has no Livepatch; nothing here applies, and nothing needs turning off.
|
||
|
||
For hosts without Livepatch, see [Rebooting automatically](#rebooting-automatically).
|
||
|
||
## Rebooting automatically
|
||
|
||
kernelwatch tells you a host needs a reboot; it never reboots anything. On hosts
|
||
without Livepatch, unattended-upgrades can do it: after a run that leaves
|
||
`/run/reboot-required` (a new kernel, libc, systemd), it reboots the host at a
|
||
set time. kernelwatch then confirms the reboot happened.
|
||
|
||
unattended-upgrades has to be installed and enabled first. Ubuntu Server has
|
||
it already; on Debian:
|
||
|
||
```sh
|
||
sudo apt install unattended-upgrades
|
||
sudo dpkg-reconfigure -plow unattended-upgrades # answer yes
|
||
```
|
||
|
||
The host page's "unattended-upgrades" row should then say `enabled`. Its kernel
|
||
hook (`/etc/kernel/postinst.d/unattended-upgrades`) creates
|
||
`/run/reboot-required` on Debian too, which Debian's kernel packages don't do
|
||
themselves.
|
||
|
||
Then turn the reboots on with a file of your own, so package upgrades never
|
||
overwrite it. Settings in later files win over `50unattended-upgrades`:
|
||
|
||
```sh
|
||
sudo tee /etc/apt/apt.conf.d/52automatic-reboot <<'EOF'
|
||
Unattended-Upgrade::Automatic-Reboot "true";
|
||
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
|
||
EOF
|
||
apt-config dump | grep Automatic-Reboot # check it took
|
||
```
|
||
|
||
Or from your workstation, for one host:
|
||
|
||
```sh
|
||
printf '%s\n' 'Unattended-Upgrade::Automatic-Reboot "true";' \
|
||
'Unattended-Upgrade::Automatic-Reboot-Time "03:30";' |
|
||
ssh -t web01 'sudo tee /etc/apt/apt.conf.d/52automatic-reboot'
|
||
```
|
||
|
||
Choosing the times:
|
||
|
||
- **Pick a time between midnight and 05:00.** `apt-daily-upgrade.timer` runs
|
||
unattended-upgrades between 06:00 and 07:00, and the reboot then waits for the
|
||
next occurrence of `Automatic-Reboot-Time`. A time in that window or just
|
||
after it can leave the host in `reboot` for nearly a full day, and the
|
||
[reboot alert](alerts.md#stale-host-reboot-and-update-alerts-ntfy) fires
|
||
after `status_alert_after_hours` (default 24). A time before 05:00 keeps the
|
||
wait under a day.
|
||
- **Stagger them.** Give hosts that depend on each other different times, half
|
||
an hour or more apart. That includes a database and the services that use it,
|
||
an SSH jump host and the hosts behind it, and redundant pairs. Then one
|
||
that doesn't come back is a single problem, not an outage.
|
||
- **Give the dashboard host its own slot.** While it's down nothing gets
|
||
alerted, though the [heartbeat](alerts.md#heartbeat-is-kernelwatch-itself-running)
|
||
notices if it stays down. It's best rebooted when nothing else is.
|
||
- Leave out `Automatic-Reboot-Time` (or set it to `now`) to reboot right after
|
||
the run, around 06:00–07:00.
|
||
- `Unattended-Upgrade::Automatic-Reboot-WithUsers "false"` skips the reboot
|
||
while anyone is logged in. A host someone stays logged into then never
|
||
reboots, and kernelwatch alerts after a day.
|
||
|
||
How kernelwatch shows it:
|
||
|
||
- After the upgrade the host is in `reboot` with the reason, such as "kernel:
|
||
running 6.8.0-136-generic, 6.8.0-138-generic installed".
|
||
- The agent reports 2 minutes after boot, so the host goes back to `ok` within
|
||
minutes of the reboot, and the host page's Uptime starts again.
|
||
- If it doesn't come back, it goes `stale` after `stale_after_hours` (default 3)
|
||
and you get the stale alert.
|
||
- If the reboot never happens (unattended-upgrades failing, a logged-in user
|
||
with `WithUsers "false"`, an upgrade you ran by hand that unattended-upgrades
|
||
had nothing to do with), the host stays in `reboot` and you get the reboot
|
||
alert after `status_alert_after_hours`. A failing unattended-upgrades also
|
||
shows up as its own reason.
|
||
|
||
Things to know:
|
||
|
||
- **Livepatch hosts:** leave this off there. Livepatch's cover only applies to
|
||
kernel reboots, and with `Automatic-Reboot` on, unattended-upgrades reboots
|
||
for the new kernel anyway, which throws that cover away. kernelwatch tells
|
||
you when the cover runs out.
|
||
- **Services needing a restart** (outdated libraries) never cause a reboot;
|
||
the host page lists them. On Ubuntu, needrestart restarts most of them after
|
||
the upgrade. On Debian with `--with-needrestart`, kernelwatch sets
|
||
needrestart to only list them, so run `sudo needrestart -r a`.
|
||
- **Turning it off:** delete `/etc/apt/apt.conf.d/52automatic-reboot`.
|
||
|
||
## Deploying to many hosts
|
||
|
||
`agent/deploy.sh` does all of the above over SSH from your workstation's
|
||
checkout, so hosts need neither git nor Gitea access. Set it up once:
|
||
|
||
```sh
|
||
cp agent/deploy.conf.example agent/deploy.conf # SERVER_URL, DASHBOARD (ssh target)
|
||
cp agent/hosts.example agent/hosts # optional; --register fills it in
|
||
```
|
||
|
||
Then:
|
||
|
||
```sh
|
||
agent/deploy.sh --register web01 db01 # register on the dashboard + install
|
||
agent/deploy.sh # upgrade every host in agent/hosts
|
||
agent/deploy.sh web01 # upgrade one
|
||
agent/deploy.sh --rotate web01 # new token, reinstall
|
||
agent/deploy.sh --dry-run # show the plan
|
||
agent/deploy.sh -- --with-needrestart # pass options through to install.sh
|
||
agent/deploy.sh -- --with-apt-update # refresh package lists before each report
|
||
agent/deploy.sh --allow-outdated # deploy even if this checkout is behind upstream
|
||
```
|
||
|
||
For each host it copies the agent into a private temp directory and runs
|
||
`install.sh`, which sends a first report, then deletes the temp directory.
|
||
With `--register`/`--rotate`, it also runs
|
||
`sudo kernelwatch add-host --token-only` on the dashboard host and passes the
|
||
token to the host on SSH stdin. The token never appears on a command line or
|
||
in your terminal. A plain run is an upgrade: config and token stay as they
|
||
are. You'll get sudo prompts on each host, and on the dashboard when
|
||
registering, unless you have passwordless sudo.
|
||
|
||
Run it as yourself, not with `sudo`: it connects with your own SSH config and
|
||
keys and runs `sudo` on each host itself. Under `sudo`, ssh would read root's
|
||
config instead, so a custom `Port` or `IdentityFile` disappears and it tries
|
||
port 22. It refuses to run that way.
|
||
|
||
Before deploying, it fetches your checkout's upstream branch. If the checkout
|
||
is behind (you pulled on the dashboard host but not here, say), it would ship an
|
||
older agent than the server expects, and the dashboard would keep saying
|
||
"agent is older" after a deploy that looked fine. So it asks before going on,
|
||
or refuses when it isn't run from a terminal; `git pull` first, or pass
|
||
`--allow-outdated` to deploy it anyway. `--dry-run` only warns. If the fetch
|
||
fails (offline, say), it warns and deploys.
|
||
|
||
Both files are git-ignored. Host names default to each host's `hostname -s`;
|
||
put `<ssh target> <name>` in `agent/hosts` to override. For a host your
|
||
workstation can't reach directly (e.g. IPv6-only while you're on IPv4), give it
|
||
a jump host in `~/.ssh/config` and `deploy.sh` works unchanged:
|
||
|
||
```
|
||
Host zeus
|
||
ProxyJump eurus
|
||
```
|