unit

package
v0.2.0-dev.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 12 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

Index

Constants

View Source
const (
	RefreshOK         = "ok"
	RefreshRolledBack = "rolled_back"
	RefreshFailed     = "failed"
)
View Source
const (
	CapabilityRefresh = "unit-refresh/1"
	ServiceName       = "mistgate-node.service"
	RefreshUnitName   = "mistgate-unit-refresh"
	RefreshAckFile    = "unit-refresh.ack"
)
View Source
const Generation = 3

Generation is written into the hardened mistgate-node.service unit as MISTGATE_UNIT_GEN.

View Source
const RefreshOutcomeFile = "unit-refresh.outcome"

Variables

View Source
var ErrBusy = errors.New("busy")
View Source
var ErrLaunch = errors.New("unit refresh launch failed")
View Source
var ErrPreflight = errors.New("unit refresh preflight failed")

Functions

func DetectSystemdService

func DetectSystemdService(cgroup []byte, service string) (managed, matches bool)

DetectSystemdService reports whether the process belongs to a systemd cgroup and whether it belongs to the exact requested service. Cgroup path components are compared as complete names so similarly named units do not match.

func RefreshBusy

func RefreshBusy(ctx context.Context) error

RefreshBusy reports whether the fixed transient refresh unit is already loaded. A current-generation agent uses it before returning a no-op so a second apply during the installer restart window still reports busy.

func RemoveRefreshOutcome

func RemoveRefreshOutcome(path string) error

func RestorePreviousUnit

func RestorePreviousUnit(path string) error

func SystemdRun

func SystemdRun(exe, stateDir string, fromGen int, validate func(context.Context) error) func(context.Context, func()) error

SystemdRun starts the installed binary in a transient root unit so it can rewrite its own systemd unit outside its service sandbox. The fixed unit name makes concurrent refresh attempts fail closed. The helper waits for an ack file so the panel's CommandResult is sent before it can restart this service.

func WaitRefreshAck

func WaitRefreshAck(ctx context.Context, path, token string) error

func WriteRefreshAck

func WriteRefreshAck(path, token string) error

func WriteRefreshOutcome

func WriteRefreshOutcome(path string, outcome RefreshOutcome) error

func WriteUnitWithPrevious

func WriteUnitWithPrevious(path string, contents []byte) (bool, error)

Types

type CommandRunner

type CommandRunner func(context.Context, string, ...string) ([]byte, error)

type RefreshConfig

type RefreshConfig struct {
	UnitPath       string
	Binary         string
	StateDir       string
	FromGen        int
	ToGen          int
	RAMBytes       uint64
	Render         UnitRenderer
	Run            CommandRunner
	Now            func() time.Time
	Sleep          func(context.Context, time.Duration)
	WaitTimeout    time.Duration
	CommandTimeout time.Duration
	StableFor      time.Duration
	PollInterval   time.Duration
}

type RefreshOutcome

type RefreshOutcome struct {
	At      time.Time `json:"at"`
	FromGen int       `json:"from_gen"`
	ToGen   int       `json:"to_gen"`
	Result  string    `json:"result"`
	Reason  string    `json:"reason,omitempty"`
}

func ReadRefreshOutcome

func ReadRefreshOutcome(path string) (RefreshOutcome, error)

func RefreshInstall

func RefreshInstall(ctx context.Context, c RefreshConfig) (RefreshOutcome, error)

RefreshInstall replaces the unit atomically, then reloads and restarts the service. A service that does not remain active for the stability window is rolled back to the saved unit and restarted again.

type UnitRenderer

type UnitRenderer func(bin, stateDir string, ramBytes uint64) (string, error)

Jump to

Keyboard shortcuts

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