Documentation
¶
Overview ¶
Package supervisor manages the lifecycle of a single supervised service process: spawning, log capture, restart policy, and graceful cancellation.
Index ¶
- Variables
- func KillTree(pid int, grace time.Duration)
- func PIDFilePath(stateDir string) string
- func ProcStartTimeMs(pid int) (int64, bool)
- func RemovePIDFile(stateDir string)
- func SameProcess(pid int, wantStartMs int64) bool
- func WritePIDFile(stateDir string) error
- type RestartMode
- type RestartPolicy
- type Supervisor
Constants ¶
This section is empty.
Variables ¶
var DefaultPolicy = RestartPolicy{ Mode: RestartOnFailure, MaxRestarts: 10, StartupMaxRestarts: 3, StartupGrace: 2 * time.Second, InitialDelay: 500 * time.Millisecond, MaxDelay: 30 * time.Second, ResetAfter: 60 * time.Second, }
DefaultPolicy matches the defaults in the Rust implementation.
Functions ¶
func KillTree ¶ added in v0.34.3
KillTree terminates pid and all of its descendants. Descendants are collected before any signal is sent (killing the parent reparents survivors, losing the tree). Each process gets a graceful Terminate, then a forceful Kill after grace if still alive. Cross-platform via gopsutil — used to reap orphaned service processes left by a crashed devrig, where no process-group handle from this run is available.
func PIDFilePath ¶
PIDFilePath returns the path to the devrig master PID file.
func ProcStartTimeMs ¶ added in v0.34.3
ProcStartTimeMs returns a process's creation time (milliseconds since the Unix epoch), or ok=false if it can't be inspected (gone, or no permission). Combined with the PID it forms a reuse-proof identity: a recycled PID belongs to a process with a different start time.
func SameProcess ¶ added in v0.34.3
SameProcess reports whether pid currently refers to the same process that had the given start time, guarding against PID reuse. wantStartMs == 0 means the start time is unknown (e.g. state written by an older devrig): fall back to a liveness-only check so behaviour degrades gracefully rather than refusing.
func WritePIDFile ¶
WritePIDFile writes the current process PID to the state directory.
Types ¶
type RestartMode ¶
type RestartMode int
RestartMode determines when a process should be restarted.
const ( RestartOnFailure RestartMode = iota // restart only on non-zero exit RestartAlways // restart regardless of exit code RestartNever // never restart )
type RestartPolicy ¶
type RestartPolicy struct {
Mode RestartMode
MaxRestarts uint32
StartupMaxRestarts uint32
StartupGrace time.Duration
InitialDelay time.Duration
MaxDelay time.Duration
ResetAfter time.Duration
}
RestartPolicy holds all tuning knobs for the restart loop.
func PolicyFromConfig ¶
func PolicyFromConfig(cfg *config.RestartConfig) RestartPolicy
PolicyFromConfig converts a config RestartConfig to a RestartPolicy.
type Supervisor ¶
type Supervisor struct {
Name string
Command string
WorkingDir string
Env map[string]string
Policy RestartPolicy
// contains filtered or unexported fields
}
Supervisor manages a single service process.
func New ¶
func New( name, command, workingDir string, env map[string]string, policy RestartPolicy, logs *events.Broadcaster, evts *events.Broadcaster, stateDir string, ) *Supervisor
New creates a Supervisor.