supervisor

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package supervisor manages the lifecycle of a single supervised service process: spawning, log capture, restart policy, and graceful cancellation.

Index

Constants

This section is empty.

Variables

View Source
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 PIDFilePath

func PIDFilePath(stateDir string) string

PIDFilePath returns the path to the devrig master PID file.

func RemovePIDFile

func RemovePIDFile(stateDir string)

RemovePIDFile removes the PID file.

func WritePIDFile

func WritePIDFile(stateDir string) error

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.

func (*Supervisor) Run

func (s *Supervisor) Run(ctx context.Context) error

Run supervises the process until ctx is cancelled or the restart budget is exhausted. The returned error is non-nil only if the process could not be spawned at all.

Jump to

Keyboard shortcuts

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