mesh/merge-gate pass: builds new: modules/zfs, sent nowhere; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check fail: its merge-check.sh failed: --- FAIL: TestASnapshotIsAnsweredFromTheListAfterwardsAndRecorded (0.00s)
mesh/delivery superseded: a newer head of the same pull request
The home server's pool holds the operator's media library, and no mesh tool could say whether it is healthy, how full it is, when it was last scrubbed or what snapshots exist; the only way was a login. This module reads all of it with fixed zfs and zpool commands (list, get, status, iostat, events, history) and has one act, zfs_snapshot, which only adds a snapshot: refused for an unknown dataset, a name outside [A-Za-z0-9._-], an existing snapshot or no why; run as sudo -n zfs snapshot -- ds@name; answered from zfs list afterwards, with any other snapshot that came or went meanwhile; recorded as the event snapshot.taken. No destroy, rollback, set or send exists, and a test holds every command to its verb. Health (ADR 0240): zfs_health on the watch process, unhealthy for a pool not ONLINE, device or data errors, a pool past 90 % full or no ZFS at all; past 80 % and a scrub older than 35 days are warnings. Beside it, the event follower (zpool events -f, as root) keeps ZFS's errors in its journal past a reboot and is judged by its unit, the check the module does not run itself. No seat (ADR 0121), no package: ZFS is the machine's.
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// WatchEvery is how often the watch looks at the pools.
|
|
const WatchEvery = time.Minute
|
|
|
|
// The module's one long-running process (`zfs-tools watch`), run by the node-engine. It is what the
|
|
// module's health is declared on (novox/hq ADR 0240: a tool check stands on a long-running resource): the
|
|
// node-engine judges the process alive, and asks zfs_health whether the pools are. The watch itself
|
|
// writes no file and changes nothing: each minute it reads the pools, and says in its journal when their
|
|
// health changes, so the journal holds when a pool went DEGRADED and when it came back.
|
|
|
|
// Watch keeps the last verdict, to say only changes.
|
|
type Watch struct {
|
|
M *Machine
|
|
Out io.Writer
|
|
last string
|
|
}
|
|
|
|
// Look reads the pools once and says the verdict when it changed.
|
|
func (w *Watch) Look(ctx context.Context) {
|
|
h := w.M.Health(ctx)
|
|
verdict := "healthy"
|
|
if !h.Healthy {
|
|
verdict = "UNHEALTHY"
|
|
}
|
|
line := verdict + ": " + h.Why
|
|
if line != w.last {
|
|
fmt.Fprintf(w.Out, "%s %s\n", w.M.Now().Format(time.RFC3339), line)
|
|
w.last = line
|
|
}
|
|
}
|
|
|
|
// Run looks every WatchEvery until the context ends.
|
|
func (w *Watch) Run(ctx context.Context) {
|
|
w.Look(ctx)
|
|
t := time.NewTicker(WatchEvery)
|
|
defer t.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
w.Look(ctx)
|
|
}
|
|
}
|
|
}
|