Documentation
¶
Index ¶
- Variables
- func Run(ctx context.Context, opts RunOptions) error
- type Controller
- func (c *Controller) Restart(ctx context.Context, opts StartOptions) (StartResult, error)
- func (c *Controller) StartDetached(ctx context.Context, opts StartOptions) (StartResult, error)
- func (c *Controller) Status(_ context.Context) (contracts.DaemonStatus, error)
- func (c *Controller) Stop(ctx context.Context) (StopResult, error)
- func (c *Controller) WriteLogs(ctx context.Context, w io.Writer, follow bool) error
- type Paths
- type ProcessManager
- type RunOptions
- type StartOptions
- type StartProcessSpec
- type StartResult
- type StopResult
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
func (c *Controller) Status(_ context.Context) (contracts.DaemonStatus, error)
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.
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 ¶
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 ¶
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.