Documentation
¶
Overview ¶
Package daemon hosts the shared local daemon bootstrap used by CLI entrypoints.
Index ¶
- Constants
- Variables
- func ResolveDaemonLogPath(configFile string) (string, error)
- func ResolveDaemonStatePath(configFile string) (string, error)
- func Run(cfg *config.Config, opts RunOptions) error
- func WriteDaemonState(path string, state *DaemonState) error
- type BackgroundProcessSpec
- type DaemonHandle
- type DaemonState
- type DaemonStatus
- type LifecycleManager
- func (m *LifecycleManager) Restart(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
- func (m *LifecycleManager) Start(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
- func (m *LifecycleManager) Status(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
- func (m *LifecycleManager) Stop(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
- type LifecycleOptions
- type RunOptions
Constants ¶
const (
LifecycleTokenEnv = "MALT_DAEMON_LIFECYCLE_TOKEN"
)
Variables ¶
var ErrDaemonStateNotFound = errors.New("daemon state not found")
ErrDaemonStateNotFound is returned when no managed daemon state file exists.
Functions ¶
func ResolveDaemonLogPath ¶
ResolveDaemonLogPath returns the managed daemon log file path for a config selection.
func ResolveDaemonStatePath ¶
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 ¶
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.
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 ¶
func (m *LifecycleManager) Start(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
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 ¶
func (m *LifecycleManager) Stop(ctx context.Context, cfg *config.Config) (*DaemonStatus, error)
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.