supervisor

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceTypeProcess = iota
	ServiceTypeCron
)
View Source
const (
	RestartModeAlways = iota
	RestartModeOnFailure
	RestartModeNever
)

Variables

View Source
var ErrFatal = errors.New("fatal error")
View Source
var ErrProcessNotRunning = errors.New("process not running")
View Source
var ErrProcessRunning = errors.New("process already started")
View Source
var ErrServiceAlreadyExists = errors.New("service already exists")
View Source
var ErrServiceNotFound = errors.New("service not found")
View Source
var ErrStopProcessTimeout = errors.New("unable to stop process")

Functions

This section is empty.

Types

type CronService added in v1.1.0

type CronService interface {
	Service
	IsSingle() bool
	IsEnabled() bool
	GetSchedule() string
	SetEnabled(enabled bool)
	StopAll() error
	GetCommand() []string
	GetWorkDir() string
	GetEnv() map[string]string
	GetProcesses() []Process
	Run(t time.Time)
}

func NewCronService added in v1.1.0

func NewCronService(config *config.ServiceEntry, scheduler *gronx.Gronx) CronService

NewCronService creates a new CronService from a config.ServiceEntry

type Process added in v1.1.0

type Process interface {
	Start() error
	Stop(timeout time.Duration) error
	Kill() error

	IsRunning() bool

	OnStdout(listener chan string)
	OnStderr(listener chan string)
	OnExit(listener chan int)

	OffStdout(listener chan string)
	OffStderr(listener chan string)
	OffExit(listener chan int)

	GetPath() string
	GetArgs() []string
	GetWorkDir() string
	GetEnv() map[string]string
	GetPid() int
	GetID() string
	GetResourceStats() (*ProcessResourceStats, error)
}

func NewProcess added in v1.1.0

func NewProcess(ctx context.Context, cfg ProcessConfig) Process

type ProcessConfig added in v1.1.1

type ProcessConfig struct {
	Path    string
	Args    []string
	WorkDir string
	Env     map[string]string
}

type ProcessResourceStats added in v1.1.2

type ProcessResourceStats struct {
	CPUPercent    float64 `json:"cpu_percent"`
	MemoryRSS     uint64  `json:"memory_rss"`
	MemoryPercent float32 `json:"memory_percent"`
}

type ProcessService added in v1.1.0

type ProcessService interface {
	Service
	IsRunning() bool
	GetRetries() int
	GetRestartPolicy() RestartPolicy
	GetLastExitCode() int

	Start() error
	Stop(user bool) error
	Kill() error
	Restart() error

	// New additions:
	GetProcess() Process // The main process for this service
}

func NewProcessService added in v1.1.0

func NewProcessService(config *config.ServiceEntry) ProcessService

NewProcessService creates a new ProcessService from a config.ServiceEntry

type RestartMode added in v1.1.0

type RestartMode int

func ParseRestartMode added in v1.1.0

func ParseRestartMode(s string) RestartMode

func (RestartMode) String added in v1.1.0

func (r RestartMode) String() string

type RestartPolicy added in v1.1.0

type RestartPolicy interface {
	GetMode() RestartMode
	IsExponential() bool
	GetMaxRetries() int
	GetInitialDelay() time.Duration
	GetMaxDelay() time.Duration
}

func NewRestartPolicy added in v1.1.0

func NewRestartPolicy(config *config.RestartPolicy) RestartPolicy

NewRestartPolicy creates a new RestartPolicy from a config.RestartPolicy

type Service added in v1.1.0

type Service interface {
	GetName() string
	GetType() ServiceType
	AsProcess() ProcessService
	AsCron() CronService

	OnStdout(listener chan string)
	OnStderr(listener chan string)
	OffStdout(listener chan string)
	OffStderr(listener chan string)

	GetSerializedStats() map[string]any

	// New additions:
	ListProcesses() []Process // Expose all processes under this service
	GetProcessByID(id string) (Process, bool)
}

type ServiceType added in v1.1.0

type ServiceType int

func (ServiceType) String added in v1.1.0

func (t ServiceType) String() string

type Supervisor

type Supervisor interface {
	GetService(name string) (Service, bool)
	AddService(name string, service Service) error
	RemoveService(name string) error
	StartService(name string) error
	StopService(name string) error
	RestartService(name string) error
	Start() error
	Stop() error
	GetAllServices() map[string]Service
}

func CreateSupervisorFromConfig added in v1.1.0

func CreateSupervisorFromConfig(cfg *config.Config, serviceSelection map[string]bool, verbose bool) (Supervisor, error)

CreateSupervisorFromConfig creates a new Supervisor from a config.Config

func NewSupervisor

func NewSupervisor(verbose bool) Supervisor

NewSupervisor creates a new Supervisor instance

Jump to

Keyboard shortcuts

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