daemon

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDaemonAlreadyStarted indicates Start was called while daemon is already running.
	ErrDaemonAlreadyStarted = errors.New("daemon already started")
	// ErrDaemonRestartAfterStop indicates the daemon instance was already stopped and cannot restart.
	ErrDaemonRestartAfterStop = errors.New("daemon cannot be restarted after Stop")
)

Functions

func ResolveStartOrder

func ResolveStartOrder(services []config.ServiceSpec) ([]config.ServiceSpec, error)

ResolveStartOrder returns services in dependency-satisfying order. Uses Kahn's algorithm for topological sort.

Types

type ControlServer

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

ControlServer handles daemon control-plane requests over a UDS socket.

func NewControlServer

func NewControlServer(daemon *Daemon, reg *registry.Registry, logger *slog.Logger, startedAt time.Time) *ControlServer

NewControlServer creates a control server instance.

func (*ControlServer) Close

func (s *ControlServer) Close() error

Close stops the control server and all active client sessions.

func (*ControlServer) Start

func (s *ControlServer) Start(socketPath string) error

Start binds the unix socket and starts accepting control connections.

type Daemon

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

Daemon orchestrates managed services.

func New

func New(cfg *config.Config, logger *slog.Logger) (*Daemon, error)

New creates a daemon instance.

func (*Daemon) ProcessStates

func (d *Daemon) ProcessStates() []ProcessState

ProcessStates returns current process snapshot.

func (*Daemon) RestartService

func (d *Daemon) RestartService(ctx context.Context, name string) error

RestartService restarts one configured service by name.

func (*Daemon) Start

func (d *Daemon) Start(ctx context.Context) error

Start launches services and starts the health loop.

func (*Daemon) Stop

func (d *Daemon) Stop() error

Stop stops health loop and all services.

type HealthMonitor

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

HealthMonitor periodically checks process liveness.

func NewHealthMonitor

func NewHealthMonitor(
	logger *slog.Logger,
	manager *ProcessManager,
	interval time.Duration,
	maxRestarts int,
	services []config.ServiceSpec,
) (*HealthMonitor, error)

NewHealthMonitor creates a health monitor.

func (*HealthMonitor) Run

func (h *HealthMonitor) Run(ctx context.Context)

Run blocks and periodically logs process health status.

type HealthProbe

type HealthProbe interface {
	Check(ctx context.Context) error
}

HealthProbe checks process health beyond liveness.

type ManagedProcess

type ManagedProcess struct {
	// ID is the unique managed process identifier.
	ID string
	// Service is the owning service name.
	Service string
	// Spec is the configured service specification.
	Spec config.ServiceSpec
	// Args contains effective runtime args after instance expansion.
	Args []string
	// contains filtered or unexported fields
}

ManagedProcess keeps runtime state for one process instance.

type ProcessManager

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

ProcessManager starts/stops and tracks service processes.

func NewProcessManager

func NewProcessManager(logger *slog.Logger, stopWait time.Duration) *ProcessManager

NewProcessManager creates a process manager.

func (*ProcessManager) IsRunning

func (m *ProcessManager) IsRunning(id string) bool

IsRunning reports whether process id is currently alive.

func (*ProcessManager) RestartProcess

func (m *ProcessManager) RestartProcess(ctx context.Context, id string) error

RestartProcess restarts one managed process by id.

func (*ProcessManager) RestartService

func (m *ProcessManager) RestartService(ctx context.Context, spec config.ServiceSpec) error

RestartService restarts every process under a service name.

func (*ProcessManager) StartService

func (m *ProcessManager) StartService(ctx context.Context, spec config.ServiceSpec) error

StartService starts one service and all configured instances.

func (*ProcessManager) States

func (m *ProcessManager) States() []ProcessState

States returns a snapshot of all process states.

func (*ProcessManager) StopAll

func (m *ProcessManager) StopAll() error

StopAll stops all managed processes.

func (*ProcessManager) StopProcess

func (m *ProcessManager) StopProcess(id string) error

StopProcess gracefully terminates a process and escalates to SIGKILL on timeout.

func (*ProcessManager) StopService

func (m *ProcessManager) StopService(serviceName string) error

StopService stops all processes that belong to a service.

type ProcessState

type ProcessState struct {
	// ID is the unique managed process identifier.
	ID string
	// Service is the owning service name.
	Service string
	// PID is the OS process id for binary runtime, or 0 for non-process runtimes.
	PID int
	// Running reports whether the managed instance is currently alive.
	Running bool
}

ProcessState describes a managed process state snapshot.

Jump to

Keyboard shortcuts

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