supervisor

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 13 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of the supervisor plugin

Functions

This section is empty.

Types

type Config

type Config struct {
	// Bond supervisor process to given set of CPUs. Plugin uses taskset to assign process
	// to CPUs and uses the same hexadecimal format. Invalid value prints error but does
	// not terminate the process.
	// It is recommended to use this option only for testing, operating system CPU schedulers
	// are in general more superior in managing CPU cycles.
	SvCPUAffinityMask string `json:"sv-cpu-affinity-mask"`

	// A list of programs started by the supervisor.
	Programs []Program

	// A list of hooks managed by supervisor plugin. Hooks are additional commands or scripts
	// called after some specific process events.
	Hooks []Hook
}

Config represents supervision setup where programs will be started at the beginning and hooks are special commands which are executed when certain event related to one of the processes occurs

func NewEmptyConfig

func NewEmptyConfig() *Config

NewEmptyConfig prepares empty configuration ready to populate from the file

type Deps

type Deps struct {
	infra.PluginDeps
	PM pm.ProcessManager
}

Deps are supervisor plugin dependencies

type EventType

type EventType int

EventType represents type of the given event

const (
	// ProcessStatus represents events about process status
	ProcessStatus EventType = 1
)

func (EventType) String

func (e EventType) String() string

type Hook

type Hook struct {
	// Command which will be executed
	Cmd string `json:"cmd"`

	// Command arguments
	CmdArgs []string `json:"cmd-args"`
}

Hook is a procedure called when a program gets into certain state.

type Option

type Option func(*Plugin)

Option is a function that can be used in the NewPlugin to customize plugin options

func UseConf

func UseConf(conf Config) Option

UseConf returns an option which injects a particular configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns an option that can inject custom dependencies

type Plugin

type Plugin struct {
	Deps
	// contains filtered or unexported fields
}

Plugin is a supervisor plugin representation

func NewPlugin

func NewPlugin(opts ...Option) *Plugin

NewPlugin creates a new supervisor plugin with the provided options

func (*Plugin) Close

func (p *Plugin) Close() error

Close local resources

func (*Plugin) GetProgramByName

func (p *Plugin) GetProgramByName(reqName string) pm.ProcessInstance

GetProgramByName returns the process instance of a given program

func (*Plugin) GetProgramNames

func (p *Plugin) GetProgramNames() (names []string)

GetProgramNames returns names of all running process instances

func (*Plugin) Init

func (p *Plugin) Init() error

Init supervisor config file, start event watcher and programs

type Program

type Program struct {
	// Name is an optional parameter, if not set it will be derived from the executable
	Name string `json:"name"`

	// ExecutablePath is a path to the binary file, required field
	ExecutablePath string `json:"executable-path"`

	// ExecutableArgs is a list of arguments passed to the binary
	ExecutableArgs []string `json:"executable-args"`

	// LogfilePath is defined when the log output should be written to the file. No file
	// is written if not set
	LogfilePath string `json:"logfile-path"`

	// Number of automatic restarts. Note that any termination hooks are executed also
	// when the program is restarted since the operating system sends events in order
	// termination -> starting -> sleeping/idle
	Restarts int `json:"restarts"`

	// Bond process to given set of CPUs. Plugin uses taskset to assign process to CPUs
	// and uses the same hexadecimal format. Invalid value prints error message but does
	// not terminate the process.
	// Note: use only when you know what you are doing, do not try to outsmart OS CPU
	// scheduling. If a program has its own config file to manage CPUs, prioritize it.
	// Keep in mind that incorrect use may slow down certain applications or that the
	// application may contain its own CPU manager which overrides this value.
	// Warning: Locking process to CPU does NOT keep other processes off that CPU.
	CPUAffinityMask string `json:"cpu-affinity-mask"`

	// This field can postpone CPU affinity setup for given time. Some processes may
	// manipulate CPU scheduling during startup, this option allows to "bypass" it,
	// waiting until the process is fully loaded and then lock it.
	CPUAffinitySetupDelay time.Duration `json:"cpu-affinity-setup-delay"`
}

Program is a single program representation

type Supervisor

type Supervisor interface {
	// GetProgramNames returns names of all running program instances
	GetProgramNames() []string
	// GetProgramByName returns the process instance of a given program
	GetProgramByName(name string) pm.ProcessInstance
}

Supervisor is a simple interface to gather information about running programs

type SvLogger

type SvLogger struct {
	// contains filtered or unexported fields
}

SvLogger is a logger object compatible with the process manager. It uses writer to print log to stdout or a file

func NewSvLogger

func NewSvLogger(logfilePath string) (svLogger *SvLogger, err error)

NewSvLogger prepares new supervisor logger for given process.

func (*SvLogger) Close

func (l *SvLogger) Close() error

Close the file if necessary

func (*SvLogger) Write

func (l *SvLogger) Write(p []byte) (n int, err error)

Write message to the file or stdout

Jump to

Keyboard shortcuts

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