Documentation
¶
Overview ¶
Package host runs plugin processes of any kind: it finds them, decides which binaries it trusts, starts them through a Launcher, restarts one that crashes with a backoff, and stops them all when the daemon stops. What a kind does with a started process belongs to the kind's adapter, such as internal/plugins/source; the host names no kind.
Index ¶
- Constants
- Variables
- func ChecksumsFile(stateDir string) string
- func InstalledDir(stateDir string) string
- func Trusted(p Plugin, trust string, recorded Checksums) (checksum []byte, why string, err error)
- type Checksums
- type ExecLauncher
- type Host
- type Kind
- type Plugin
- type Root
- type Run
- type Settings
Constants ¶
const ( DefaultMinBackoff = time.Second DefaultMaxBackoff = 5 * time.Minute DefaultPoll = time.Second DefaultStopTimeout = 5 * time.Second )
Defaults of a Host's zero fields.
const TrustPath = "path"
TrustPath is the [plugins.<id>] trust that runs a binary by its path.
Variables ¶
var ErrUntrusted = errors.New("untrusted plugin binary")
ErrUntrusted is a plugin binary the host does not run.
Functions ¶
func ChecksumsFile ¶
ChecksumsFile is where install records the bundled plugins' checksums, under the state directory.
func InstalledDir ¶
InstalledDir is where install places the bundled plugins of the release it runs from, under the state directory.
func Trusted ¶
Trusted is how p's binary runs: the checksum it must have, nil to run it by its path, and why. trust is p's [plugins.<id>] trust. A bundled plugin runs only with the checksum its install recorded. Any other binary, and a bundled one no install recorded, runs only with trust = "path", which only the user writes.
Types ¶
type Checksums ¶
Checksums are the SHA-256 checksums of the bundled plugins' binaries an install recorded, by id.
func ReadChecksums ¶
ReadChecksums reads path, one "<hex sha256> <id>" line per binary as sha256sum writes them; a missing file records none.
type ExecLauncher ¶
type ExecLauncher struct{}
ExecLauncher starts plugin binaries as children of the daemon, each the leader of a process group procgroup lists, so a daemon that exits, or the next one after a crash, stops what they started.
type Host ¶
type Host struct {
Launcher plugin.Launcher
Kinds []Kind
Logf func(format string, args ...any)
// MinBackoff is the wait before restarting a plugin that crashed; it
// doubles after each restart that crashes before MaxBackoff passed, up
// to MaxBackoff, and is MinBackoff again after a run that lasted longer.
MinBackoff, MaxBackoff time.Duration
// Poll is how often the host checks that a plugin process runs.
Poll time.Duration
// StopTimeout bounds each kind's Stop at shutdown.
StopTimeout time.Duration
// contains filtered or unexported fields
}
Host runs plugins. Its zero durations take the defaults.
type Kind ¶
type Kind interface {
Kind() plugin.Kind
// Start connects the kind of plugin m's freshly started process.
Start(ctx context.Context, m *manifest.Manifest, c *plugin.Client) error
// Stop asks the kind of plugin id to stop, before the host kills it.
Stop(ctx context.Context, id string)
// Down says plugin id's process ended or did not start.
Down(id string)
}
Kind is the adapter of one plugin kind, which connects the kind of a started process to the daemon.
type Plugin ¶
type Plugin struct {
Manifest *manifest.Manifest
// Dir is the plugin's directory, which holds plugin.toml, the binary
// and its profile layer.
Dir string
// Binary is the plugin's binary in Dir; "" when Dir holds none, as a
// plugin compiled into the daemon has none.
Binary string
// Bundled says Dir is in the bundled directory beside the daemon's
// binary, where a release installs its plugins.
Bundled bool
}
Plugin is a plugin found on disk: its manifest, its directory and its binary.
type Run ¶
Run is a plugin the host runs: its manifest and how it starts.
func Runs ¶
func Runs(ps []Plugin, s Settings, recorded Checksums, env []string, logger hclog.Logger) (runs []Run, why map[string]string, err error)
Runs are the plugins of ps the host runs: those enabled, with a binary it trusts. A plugin with no binary, compiled into the daemon, is not one. An untrusted binary is left out and named in the error, as ErrUntrusted; why says how each that runs is trusted, by id.