host

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 18 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 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

View Source
const (
	DefaultMinBackoff  = time.Second
	DefaultMaxBackoff  = 5 * time.Minute
	DefaultPoll        = time.Second
	DefaultStopTimeout = 5 * time.Second
)

Defaults of a Host's zero fields.

View Source
const TrustPath = "path"

TrustPath is the [plugins.<id>] trust that runs a binary by its path.

Variables

View Source
var ErrUntrusted = errors.New("untrusted plugin binary")

ErrUntrusted is a plugin binary the host does not run.

Functions

func ChecksumsFile

func ChecksumsFile(stateDir string) string

ChecksumsFile is where install records the bundled plugins' checksums, under the state directory.

func InstalledDir

func InstalledDir(stateDir string) string

InstalledDir is where install places the bundled plugins of the release it runs from, under the state directory.

func Trusted

func Trusted(p Plugin, trust string, recorded Checksums) (checksum []byte, why string, err error)

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

type Checksums map[string][]byte

Checksums are the SHA-256 checksums of the bundled plugins' binaries an install recorded, by id.

func ReadChecksums

func ReadChecksums(path string) (Checksums, error)

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.

func (ExecLauncher) Launch

Launch starts spec's binary and completes the handshake, checking its checksum when spec has one.

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.

func (*Host) Start

func (h *Host) Start(ctx context.Context, runs []Run)

Start runs each of runs, each in a goroutine of its own, until ctx ends; Wait waits for them.

func (*Host) Wait

func (h *Host) Wait()

Wait waits for every plugin Start ran to stop; each run kills the process it launched before it returns, so none is left: there is no reattach. It leaves the plugin processes of another host alone.

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.

func Discover

func Discover(roots ...Root) ([]Plugin, error)

Discover reads every <root>/<id>/plugin.toml. A plugin found in more than one root is the first root's: a user's directory overrides a bundled plugin of the same id. A directory whose manifest does not load, or whose id is not its name, is left out and named in the error.

func (Plugin) ID

func (p Plugin) ID() string

ID is the plugin's id.

type Root

type Root struct {
	Dir     string
	Bundled bool
}

Root is a directory of plugin directories, one per id.

func Roots

func Roots(configDir, stateDir, exe string) []Root

Roots are where plugins are found: the user's, <config>/plugins; the bundled ones install placed, InstalledDir; then the bundled directory beside the binary, <exe dir>/plugins, where a release and a development build keep them.

type Run

type Run struct {
	Manifest *manifest.Manifest
	Spec     plugin.Spec
}

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.

type Settings

type Settings interface {
	PluginEnabled(id string) bool
	PluginTrust(id string) string
}

Settings are what the configuration says of each plugin.

Jump to

Keyboard shortcuts

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