daemon

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStartInProgress = errors.New("daemon start already in progress")

ErrStartInProgress is returned when another process is currently starting or running the daemon for the same ccx root.

Functions

func Run

func Run(ctx context.Context, opts RunOptions) error

Run starts the foreground daemon and blocks until ctx or an OS termination signal stops it.

Types

type Controller

type Controller struct {
	Root           string
	Version        string
	Executable     string
	Process        ProcessManager
	StartupTimeout time.Duration
	StopTimeout    time.Duration
	LockStaleAfter time.Duration
}

Controller owns daemon lifecycle operations for one ccx root.

func (*Controller) Restart

func (c *Controller) Restart(ctx context.Context, opts StartOptions) (StartResult, error)

Restart stops any running daemon and starts a detached one.

func (*Controller) StartDetached

func (c *Controller) StartDetached(ctx context.Context, opts StartOptions) (StartResult, error)

StartDetached starts a foreground daemon child unless one is already alive.

func (*Controller) Status

Status reads daemon runtime files and verifies the recorded process is alive.

func (*Controller) Stop

func (c *Controller) Stop(ctx context.Context) (StopResult, error)

Stop gracefully terminates a running daemon and marks stale state stopped.

func (*Controller) WriteLogs

func (c *Controller) WriteLogs(ctx context.Context, w io.Writer, follow bool) error

WriteLogs writes daemon.log to w and optionally follows new bytes until ctx is cancelled.

type Paths

type Paths struct {
	Root       string
	PIDPath    string
	StatusPath string
	LogPath    string
	LockPath   string
	DBPath     string
}

Paths are the runtime files owned by one daemon root.

func RuntimePaths

func RuntimePaths(root string) Paths

RuntimePaths returns the daemon runtime paths for root.

type ProcessManager

type ProcessManager interface {
	Alive(pid int) bool
	Matches(pid int, expectedExecutable string) bool
	Identity(pid int) (string, bool)
	StartDetached(ctx context.Context, spec *StartProcessSpec) (int, error)
	Terminate(pid int) error
}

ProcessManager abstracts process operations for lifecycle tests.

type RunOptions

type RunOptions struct {
	Root         string
	Version      string
	Port         int
	PollInterval time.Duration
	OnStatus     func(contracts.DaemonStatus)
}

RunOptions configures a foreground daemon runtime.

type StartOptions

type StartOptions struct {
	Port         int
	PollInterval time.Duration
}

StartOptions controls daemon start behavior.

type StartProcessSpec

type StartProcessSpec struct {
	Root       string
	Version    string
	StartToken string
	Executable string
	Args       []string
	Env        []string
	LogPath    string
}

StartProcessSpec describes the foreground daemon child used by detached start. Tests use Root/Version to synthesize the child status file.

type StartResult

type StartResult struct {
	Status         contracts.DaemonStatus `json:"status"`
	Started        bool                   `json:"started"`
	AlreadyRunning bool                   `json:"already_running"`
}

StartResult is returned by StartDetached.

type StopResult

type StopResult struct {
	Status  contracts.DaemonStatus `json:"status"`
	Stopped bool                   `json:"stopped"`
}

StopResult is returned by Stop.

Jump to

Keyboard shortcuts

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