Documentation
¶
Overview ¶
Package supervisor manages the lifecycle of long-running daemons (cm serve, bd daemon) that NTM spawns. It handles port allocation, health monitoring, and clean shutdown.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
SessionID string
ProjectDir string
HealthInterval time.Duration // Default: 5s
MaxRestarts int // Default: 5
RestartBackoffMax time.Duration // Default: 60s
}
Config holds supervisor configuration.
type DaemonSpec ¶
type DaemonSpec struct {
Name string `json:"name"` // Unique identifier: "cm", "bd", "am"
Command string `json:"command"` // Command to run: "cm", "bd"
Args []string `json:"args"` // Arguments: ["serve", "--port", "8765"]
HealthURL string `json:"health_url"` // Health check URL: "http://127.0.0.1:8765/health/liveness" or "/health"
HealthCmd []string `json:"health_cmd"` // Health check command: ["bd", "daemon", "--health"]
PortFlag string `json:"port_flag"` // Flag to specify port: "--port"
DefaultPort int `json:"default_port"` // Default port if none specified
WorkDir string `json:"work_dir"` // Working directory for the daemon
Env []string `json:"env"` // Additional environment variables
}
DaemonSpec defines how to start and manage a daemon.
func DefaultSpecs ¶
func DefaultSpecs() []DaemonSpec
DefaultSpecs returns the default daemon specs for NTM.
type DaemonState ¶
type DaemonState string
DaemonState represents the current state of a managed daemon.
const ( StateStarting DaemonState = "starting" StateRunning DaemonState = "running" StateStopping DaemonState = "stopping" StateStopped DaemonState = "stopped" StateFailed DaemonState = "failed" StateRestarting DaemonState = "restarting" )
type ManagedDaemon ¶
type ManagedDaemon struct {
Spec DaemonSpec `json:"spec"`
State DaemonState `json:"state"`
PID int `json:"pid"`
Port int `json:"port"`
StartedAt time.Time `json:"started_at"`
LastHealth time.Time `json:"last_health"`
Restarts int `json:"restarts"`
OwnerID string `json:"owner_id"` // Session ID that owns this daemon
// contains filtered or unexported fields
}
ManagedDaemon represents a running daemon process.
type PIDFileInfo ¶
type PIDFileInfo struct {
PID int `json:"pid"`
Port int `json:"port"`
OwnerID string `json:"owner_id"`
Command string `json:"command"`
StartedAt time.Time `json:"started_at"`
}
PIDFileInfo stores information written to PID files.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor manages the lifecycle of multiple daemons for an NTM session.
func New ¶
func New(cfg Config) (*Supervisor, error)
New creates a new Supervisor for the given session.
func (*Supervisor) GetDaemon ¶
func (s *Supervisor) GetDaemon(name string) (*ManagedDaemon, bool)
GetDaemon returns a daemon by name.
func (*Supervisor) Shutdown ¶
func (s *Supervisor) Shutdown() error
Shutdown stops all owned daemons and cancels the supervisor context.
func (*Supervisor) Start ¶
func (s *Supervisor) Start(spec DaemonSpec) error
Start starts a daemon with the given spec.
func (*Supervisor) Status ¶
func (s *Supervisor) Status() map[string]*ManagedDaemon
Status returns the status of all managed daemons. Returns deep copies to prevent data races with slice fields.
func (*Supervisor) Stop ¶
func (s *Supervisor) Stop(name string) error
Stop stops a daemon gracefully.
func (*Supervisor) StopAll ¶
func (s *Supervisor) StopAll() error
StopAll stops all daemons owned by this session.