Documentation
¶
Overview ¶
Package supervisor gives the daemon an owner.
`kivgraph daemon` is a long-lived process that nothing starts and nothing restarts. That is why `serve` is still what a client registration names by default: a `command` entry is owned by the client that spawns it, while a `url` entry points at a process which, today, exists only for as long as the shell that launched it. Registering every client against a daemon nobody owns trades memory for a failure where every client loses its tools at once and nothing brings them back.
Measured on a workspace of 108.737 symbols, with eight idle clients, one daemon holds 10-13 MB of private pages against 77-81 for eight servers, and peaks at 26-29 MB against 179-186. That is the saving this package exists to make safe to depend on.
What it installs is the platform's own supervisor -- a launchd agent on darwin, a systemd user unit on linux -- because writing a second process manager inside a code-graph tool is not a thing this project should own.
The unit is per state directory, not per machine or per user. A daemon serves one state directory (internal/daemon.SocketName says why: two configurations pointing at different directories get different daemons, so a client never reaches a graph built from someone else's repositories), so two configurations must be able to hold two supervised daemons at once. The label carries a digest of the directory to make that true, and Status prints it rather than leaving the operator to guess which unit serves what.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIncompleteSpec = errors.New("supervisor: a spec needs an executable and a state directory")
ErrIncompleteSpec reports a spec that names no executable or no state directory. Both are absolute paths in the installed file, so neither can be inferred later.
var ErrUnsupportedPlatform = errors.New("supervisor: this platform has no supported process supervisor")
ErrUnsupportedPlatform reports a platform with no supervisor this package knows how to drive. It is a declared limitation and never a silent no-op: a caller that cannot install a supervisor must be able to say so.
Functions ¶
This section is empty.
Types ¶
type Report ¶
Report is what an operation observed. Path is empty when the platform has no supervisor, and Detail always says something a reader can act on.
func Install ¶
Install writes the unit and asks the supervisor to load it.
It is idempotent: an install over a unit that already describes this spec reloads it rather than reporting a change, because a caller that runs it twice should not have to know which time was the first.
type Spec ¶
type Spec struct {
// Executable is the absolute path of the kivgraph binary to run. It is
// recorded rather than resolved at start time because an installed
// supervisor outlives the shell that installed it, and `kivgraph update`
// replaces the bundle in place at the same path.
Executable string
// StateDirectory is the directory whose daemon this is. It is the
// identity: it decides the label, so two configurations get two units.
StateDirectory string
// ConfigPath, when set, is passed as --config. Empty means the daemon
// resolves its own configuration, which is what a default install wants.
ConfigPath string
// Address, when set, is passed as --addr. Empty means the daemon's own
// default bind.
Address string
// AllowRemote is passed as --allow-remote, and it travels with Address for
// a reason: the daemon refuses a non-loopback bind without it, so a unit
// recording one and not the other would start a daemon that exits.
AllowRemote bool
}
Spec is the daemon a supervisor should keep running.
func (Spec) Label ¶
Label returns the supervisor identifier for a spec.
The digest is of the cleaned absolute state directory, so the same daemon always gets the same label and two daemons never collide. Eight hex characters is enough to separate the handful of state directories one user has, and short enough to read in `launchctl list`.
type State ¶
type State string
State is what a supervisor knows about a spec.
const ( // StateAbsent means no unit for this spec is installed. StateAbsent State = "absent" // StateInstalled means the unit exists and the supervisor loaded it. StateInstalled State = "installed" // StateStale means the unit exists but describes a different executable // or a different daemon than the spec asks for. It is reported rather // than repaired silently: an operator who edited a unit by hand should be // told, not overruled. StateStale State = "stale" // StateUnsupported means this platform has no supervisor this package // drives. It is not a failure of the installation. StateUnsupported State = "unsupported" )