daemon

package
v0.0.4-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package daemon hosts the shared local daemon bootstrap used by CLI entrypoints.

Index

Constants

View Source
const (
	LifecycleTokenEnv = "MALT_DAEMON_LIFECYCLE_TOKEN"
)

Variables

View Source
var ErrDaemonStateNotFound = errors.New("daemon state not found")

ErrDaemonStateNotFound is returned when no managed daemon state file exists.

Functions

func ResolveDaemonLogPath

func ResolveDaemonLogPath(configFile string) (string, error)

ResolveDaemonLogPath returns the managed daemon log file path for a config selection.

func ResolveDaemonStatePath

func ResolveDaemonStatePath(configFile string) (string, error)

ResolveDaemonStatePath returns the managed daemon state file path for a config selection.

func Run

func Run(cfg *config.Config, opts RunOptions) error

Run starts the daemon HTTP API, then blocks until shutdown or a fatal server error occurs.

func WriteDaemonState

func WriteDaemonState(path string, state *DaemonState) error

WriteDaemonState writes a managed daemon state file.

Types

type BackgroundProcessSpec

type BackgroundProcessSpec struct {
	Executable string
	Args       []string
	Env        []string
	LogPath    string
}

BackgroundProcessSpec describes the daemon process to launch in the background.

type DaemonHandle added in v0.0.2

type DaemonHandle struct {
	Listen string
	// contains filtered or unexported fields
}

DaemonHandle is a running daemon instance that can be shut down.

func Start added in v0.0.2

func Start(cfg *config.Config, opts RunOptions) (*DaemonHandle, error)

Start launches the daemon in the background and returns a handle. Unlike Run, Start does not block — the caller is responsible for calling Shutdown when done.

func (*DaemonHandle) Shutdown added in v0.0.2

func (h *DaemonHandle) Shutdown(ctx context.Context) error

Shutdown gracefully stops the daemon.

type DaemonState

type DaemonState struct {
	PID            int       `json:"pid"`
	Listen         string    `json:"listen"`
	BaseURL        string    `json:"base_url"`
	ConfigPath     string    `json:"config_path"`
	LifecycleToken string    `json:"lifecycle_token,omitempty"`
	StartedAt      time.Time `json:"started_at"`
}

DaemonState is the local state recorded for a managed background daemon.

func LoadDaemonState

func LoadDaemonState(path string) (*DaemonState, error)

LoadDaemonState loads a managed daemon state file.

type DaemonStatus

type DaemonStatus struct {
	Running     bool
	Managed     bool
	PID         int
	Listen      string
	BaseURL     string
	ConfigPath  string
	StatePath   string
	LogPath     string
	StartedAt   time.Time
	HealthError error
}

DaemonStatus describes the observed daemon lifecycle state.

type LifecycleManager

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

LifecycleManager manages a daemon process started by `malt start`.

func NewLifecycleManager

func NewLifecycleManager(opts LifecycleOptions) *LifecycleManager

NewLifecycleManager creates a lifecycle manager with production defaults for any operation not supplied in opts.

func (*LifecycleManager) Restart

func (m *LifecycleManager) Restart(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)

Restart stops a managed daemon when present, then starts a new managed daemon.

func (*LifecycleManager) Start

Start launches the daemon in the background unless a healthy daemon is already running for the configured endpoint.

func (*LifecycleManager) Status

func (m *LifecycleManager) Status(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)

Status reports whether the configured daemon endpoint is healthy.

func (*LifecycleManager) Stop

Stop terminates a managed daemon process and removes its state file.

type LifecycleOptions

type LifecycleOptions struct {
	ConfigPath    string
	StatePath     string
	LogPath       string
	Executable    string
	ProcessArgs   []string
	Env           []string
	Now           func() time.Time
	StartTimeout  time.Duration
	StopTimeout   time.Duration
	PollInterval  time.Duration
	Sleep         func(time.Duration)
	StartProcess  func(BackgroundProcessSpec) (int, error)
	SignalProcess func(int) error
	HealthCheck   func(context.Context, string) error
	IdentityCheck func(context.Context, string, string) error
	GenerateToken func() (string, error)
}

LifecycleOptions configures local managed daemon process operations.

type RunOptions

type RunOptions struct {
	ListenOverride string
	APILabel       string
	LifecycleToken string
	Stdout         io.Writer
	Stderr         io.Writer
}

RunOptions configures daemon process startup.

Jump to

Keyboard shortcuts

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