supervisor

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

type Report struct {
	State  State
	Label  string
	Path   string
	Detail string
}

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

func Install(spec Spec) (Report, error)

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.

func Remove

func Remove(spec Spec) (Report, error)

Remove takes the unit out and asks the supervisor to unload it. Removing an absent unit is not an error: it is the state the caller asked for.

func Status

func Status(spec Spec) (Report, error)

Status reports what is installed without changing anything.

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

func (spec Spec) Label() (string, error)

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL