Files
kernel-automation/docs/agents.md
T
patrickandClaude Sonnet 5.5 404086ded1 Fix references that moved with the text
'above', 'below' and 'as above' pointed at sections that are now on other
pages, so they become links; server/install.sh's pointer to the README now
names docs/reverse-proxy.md; server.md gains the next steps that used to be
the following README sections.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 12:10:13 -04:00

88 lines
3.3 KiB
Markdown

# Agents
[← kernelwatch](../README.md)
## 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
```
## 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
```
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.
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
```