service

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT 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

Overview

Package service installs, loads and checks the stage 2 service units of one Codex home: launchd agents on macOS, systemd user units on Linux. Each home gets an edge (socket-activated: the service manager holds the provider port, plan decision M8) and a brain. Unit names carry the home id, so homes never share a unit. launchctl and systemctl run through an injected Runner.

Index

Constants

View Source
const (
	RoleEdge  = "edge"
	RoleBrain = "brain"
)

Roles of a home's units.

View Source
const EdgeSocket = "edge"

EdgeSocket names the edge's socket in the launchd Sockets dict and the systemd FileDescriptorName; the edge asks listen.Activated for it.

Variables

This section is empty.

Functions

func Exec

func Exec(ctx context.Context, name string, args ...string) (string, error)

Exec is the Runner that runs the command.

Types

type Ensured

type Ensured int

Ensured is what Ensure found or did.

const (
	NotSetUp Ensured = iota // a unit file is missing: run setup
	AlreadyUp
	Started
)

Ensure results.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager installs and checks the units of homes.

func New

func New(o Options) (*Manager, error)

New returns the Manager for o.GOOS.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context, homeID string) (Ensured, error)

Ensure starts a set-up home's units that are down. It does not wait for them to run.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, s Spec) error

Install writes the units of s's home and loads them. Units already installed are unloaded first, so a changed port or binary takes effect.

func (*Manager) Installed

func (m *Manager) Installed(homeID string) []Unit

Installed lists the units of a home whose file exists.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context, homeID string) []Unit

Status reports the watched units of a home: the edge's socket and the brain.

func (*Manager) StatusReadOnly added in v0.7.2

func (m *Manager) StatusReadOnly(ctx context.Context, homeID string) ([]Unit, error)

StatusReadOnly reports watched unit states and returns errors from the platform status command. It never starts or changes a unit.

func (*Manager) Uninstall

func (m *Manager) Uninstall(ctx context.Context, homeID string) ([]Unit, error)

Uninstall unloads a home's units and deletes their files. It returns the units it removed; none is not an error.

func (*Manager) Units

func (m *Manager) Units(homeID string) []Unit

Units lists the unit files of a home, installed or not.

type Options

type Options struct {
	GOOS string // "darwin" (launchd) or "linux" (systemd)
	// Home is the user's home dir; launchd agents go to Library/LaunchAgents.
	Home string
	// ConfigHome is $XDG_CONFIG_HOME; systemd user units go to
	// systemd/user in it. Empty or relative means Home/.config.
	ConfigHome string
	UID        int // launchd's gui/<uid> domain
	Run        Runner
}

Options select and place a Manager's backend.

type Runner

type Runner func(ctx context.Context, name string, args ...string) (string, error)

Runner runs a service manager command and returns its combined output.

type Spec

type Spec struct {
	HomeID   string
	HomePath string
	// StateDir is the state base the units pass as --state-dir (plan M3):
	// service managers do not see the shell's XDG_STATE_HOME.
	StateDir string
	// Config is the codex-router config file passed as --config, for the
	// same reason; empty passes none.
	Config string
	Bin    string
	Port   int
	// LogDir holds launchd's edge.log and brain.log; systemd uses the
	// journal.
	LogDir string
}

Spec is what the units of one home run.

type State

type State int

State is a unit's state as Status reports it.

const (
	Missing State = iota // no unit file: the home is not set up
	Down                 // installed, but not loaded or not running
	Up                   // loaded; for the edge, the port is held
)

Unit states.

func (State) String

func (s State) String() string

type Unit

type Unit struct {
	Role  string
	Name  string // launchd label or systemd unit name
	Path  string // unit file
	State State
	// contains filtered or unexported fields
}

Unit is one service unit of a home.

Jump to

Keyboard shortcuts

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