units

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package units is the text and install of every unit a running sprint needs. A worker's binary may import it: it writes files and loads them through the caller's loader, and it does not open the sprint's store.

Index

Constants

View Source
const (
	SeatLabel         = "nova-sprint.seat-push"
	SeatService       = "nova-sprint-seat-push.service"
	FriendSyncLabel   = "nova-sprint.friend-sync"
	FriendSyncService = "nova-sprint-friend-sync.service"
)

The labels seat install and friend sync install already write. They live here so the kind table and those verbs name one file, and so this package does not import internal/sprint (a worker's binary may import this package, and internal/sprint reaches the store).

View Source
const (
	UnitInstalled = "installed" // the kind's file is there and runs the kind's verb itself
	UnitMissing   = "missing"   // no file of the kind is there
	UnitDifferent = "different" // a file is there that runs something else, or is no unit
)

The states units --check gives a unit a running sprint needs.

Variables

View Source
var UnitKinds = []UnitKind{
	{Kind: "store", Label: "nova-redis.store", Service: "nova-redis-store.service", Tool: "nova-redis", Verb: []string{"serve"},
		Install: "nova-redis install store", What: "the sprint's store, a Redis server (nova-redis serve)"},
	{Kind: "bus", Label: "nova-redis.bus", Service: "nova-redis-bus.service", Tool: "nova-redis", Verb: []string{"serve"},
		Install: "nova-redis install bus", What: "the friends' bus, a Redis server (nova-redis serve)"},
	{Kind: "server", Label: "nova-sprint.server", Service: "nova-sprint-server.service", Tool: "nova-sprint", Verb: []string{"run", "--listen"},
		Install: "nova-sprint install server", What: "the sprint's server and its loop (nova-sprint run --listen)"},
	{Kind: "member", Label: "nova-sprint.member", Service: "nova-sprint-member.service", Tool: "nova-swarm", Verb: []string{"member"},
		Install: "nova-sprint install member", What: "this machine's fleet member (nova-swarm member)"},
	{Kind: "seat-push", Label: SeatLabel, Service: SeatService, Tool: "nova-sprint", Verb: []string{"inbox", "--wait", "--push", "seat"},
		Install: "nova-sprint install seat-push", What: "the seat's push loop (nova-sprint inbox --wait --push seat)"},
	{Kind: "friend-sync", Label: FriendSyncLabel, Service: FriendSyncService, Tool: "nova-sprint", Verb: []string{"friend", "sync", "--every"},
		Install: "nova-sprint install friend-sync", What: "the friend sync loop (nova-sprint friend sync --every)"},
	{Kind: "table", Label: "nova-sprint.table", Service: "nova-sprint-table.service", Tool: "nova-sprint", Verb: []string{"where", "--watch"},
		Install: "nova-sprint install table", What: "the live sprint table written to a file (nova-sprint where --watch)"},
	{Kind: "disk-guard", Label: "nova-swarm.disk-guard", Service: "nova-swarm-disk-guard.service", Tool: "nova-swarm", Verb: []string{"disk-guard"},
		Install: "nova-swarm install disk-guard", What: "the machine's disk upkeep, one pass every --every (nova-swarm disk-guard)"},
	{Kind: "mirror-refresh", Label: "nova-swarm.mirror-refresh", Service: "nova-swarm-mirror-refresh.service", Tool: "nova-swarm", Verb: []string{"mirror"},
		Install: "nova-swarm install mirror-refresh", What: "the bench's repository mirrors kept fresh (nova-swarm mirror)",
		Owed: "nova-swarm has no mirror verb for the unit to run"},
}

UnitKinds is every unit a running sprint needs on its coordinator's machine, in the order a machine is brought up: the store and the bus, the server, its member, the seat's loops, then the machine's upkeep.

Functions

func Dir

func Dir(goos, home string, getenv func(string) string) string

UnitDir is where a unit goes when no directory is named: the user's LaunchAgents on macOS, the systemd user directory on Linux ($XDG_CONFIG_HOME/systemd/user when that is set).

func LaunchdPlist

func LaunchdPlist(label string, args []string, env [][2]string, log string, throttle int) string

launchdPlistEvery is a launchd agent kept alive that runs args with env, its lines to log, started again no sooner than every throttle seconds.

func Load

func Load(goos, op, path string) error

LoadUnit loads (op load: unloaded first, so a changed unit is read again) or unloads the unit at path on this machine, named by its file: launchctl in the user's gui domain on macOS, its label the file's name without .plist, and systemctl --user on Linux, its service the file's name. It is the loader of every unit a nova verb installs (seat install, friend sync install, nova-sprint install, nova-redis install). Under NOVA_TEST_NO_HOST it refuses: a test gives its own loader.

func SystemdUnit

func SystemdUnit(description string, args []string, env [][2]string, restart int) string

systemdUnitEvery is a systemd user unit restarted always, no sooner than every restart seconds, that runs args with env.

func UnitArgs

func UnitArgs(goos string, b []byte) ([]string, error)

UnitArgs is the command line a unit file runs: a launchd plist's ProgramArguments, or a systemd unit's ExecStart words.

func UnitKindNames

func UnitKindNames(tool string) []string

UnitKindNames is every kind's word whose install verb is tool's, in UnitKinds' order.

Types

type Installer

type Installer struct {
	Dir          string
	Load, Unload func(path string) error
}

Installer writes units into Dir. Load loads (or loads again) the unit at a path and Unload unloads it. Both are the caller's, so a test loads nothing on the host.

func (Installer) Install

func (in Installer) Install(u ServiceUnit) (Result, error)

InstallUnit writes the unit into the installer's directory unless the file there is already this text, and loads it either way, as Install does the push loop's.

func (Installer) Remove

func (in Installer) Remove(path string) (Result, error)

removeUnit unloads the unit at path and removes it; with no file there it does nothing, and says so by Changed false.

func (Installer) Uninstall

func (in Installer) Uninstall(k UnitKind, goos string) (Result, error)

UninstallUnit unloads the kind's unit and removes its file; with no file there it does nothing, and says so by Changed false.

func (Installer) Write

func (in Installer) Write(path, text string) (Result, error)

Write writes text at path (whole, beside it first, then renamed into place) unless the file there is already this text, and loads it either way, so an install after the unit was unloaded by hand starts it again. A unit whose load fails stays written; the error says the load.

type Result

type Result struct {
	Path    string
	Changed bool
}

Result is what install or uninstall did: the unit's path, and whether the file there was written or removed.

type ServiceUnit

type ServiceUnit struct {
	Kind  UnitKind
	OS    string
	Args  []string
	Env   [][2]string
	Log   string
	Every time.Duration
}

ServiceUnit is one unit of a kind as a service: its command line, the binary first by its absolute path; its environment, names and addresses and never a secret; the file its lines go to (launchd; systemd keeps them in its journal); and Every, the least time between two starts, so a verb that does one pass and exits runs once every Every (launchd's ThrottleInterval, systemd's RestartSec; 0 is 10 s).

func (ServiceUnit) Text

func (u ServiceUnit) Text() (string, error)

Text is the unit's file: a launchd plist, or a systemd user unit.

type UnitKind

type UnitKind struct {
	Kind    string   `json:"kind"`           // the word the install verb takes
	Label   string   `json:"label"`          // the launchd label; its plist is Label.plist
	Service string   `json:"service"`        // the systemd user unit
	Tool    string   `json:"tool"`           // the nova binary the unit runs, by its base name
	Verb    []string `json:"verb"`           // the words after the binary every such unit starts with
	Install string   `json:"install"`        // the verb line that writes and loads it
	What    string   `json:"what"`           // one line: what the unit is
	Owed    string   `json:"owed,omitempty"` // what the install verb still waits on, "" when it is there
}

UnitKind is one kind of unit a running sprint needs: its file names, the nova tool it runs, the words every such unit starts with after the tool, and the verb that installs it.

func UnitKindOf

func UnitKindOf(k string) (UnitKind, bool)

UnitKindOf is the kind named k.

func (UnitKind) File

func (k UnitKind) File(goos string) string

File is the kind's unit file name on goos, "" where there is no service manager a unit is installed under.

type UnitState

type UnitState struct {
	Kind    string `json:"kind"`
	Owed    string `json:"owed,omitempty"`
	Path    string `json:"path"`
	State   string `json:"state"`
	Why     string `json:"why,omitempty"`
	Install string `json:"install"`
}

UnitState is one needed unit as units --check found it: its kind, the file it is looked for at, its state, why it is different, the verb that installs it, and what that verb still waits on when it is not there yet.

func CheckUnits

func CheckUnits(dir, goos string, kinds []UnitKind) ([]UnitState, error)

CheckUnits looks for every kind's unit in dir on goos: missing when no file is there, different when the file there does not run the kind's tool itself with the kind's verb (a nova-secrets exec, a shell, a wrapper, another verb, a file that is no unit), installed when it does. It reads files only: nothing is loaded or changed.

Jump to

Keyboard shortcuts

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