system

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateEventUp       = StateEvent("up")
	StateEventDown     = StateEvent("down")
	StateEventFinished = StateEvent("finished")
)

Service event list.

Variables

View Source
var ErrSkip = errors.New("service skipped")

ErrSkip is returned by Run when service is skipped.

View Source
var WaitConditionCheckInterval = time.Second

WaitConditionCheckInterval is time between checking for wait condition description changes.

Exposed here for unit-tests to override.

Functions

func Services

func Services(runtime runtime.Runtime) *singleton

Services returns the instance of the system services API.

func WaitForService

func WaitForService(event StateEvent, service string) conditions.Condition

WaitForService waits for service to reach some state event.

Types

type APIRestartableService

type APIRestartableService interface {
	APIRestartAllowed(runtime.Runtime) bool
}

APIRestartableService is a service which allows to be restarted via API.

type APIStartableService

type APIStartableService interface {
	APIStartAllowed(runtime.Runtime) bool
}

APIStartableService is a service which allows to be started via API.

type APIStoppableService

type APIStoppableService interface {
	APIStopAllowed(runtime.Runtime) bool
}

APIStoppableService is a service which allows to be stopped via API.

type HealthcheckedService

type HealthcheckedService interface {
	// HealtFunc provides function that checks health of the service
	HealthFunc(runtime.Runtime) health.Check
	// HealthSettings returns settings for the health check
	HealthSettings(runtime.Runtime) *health.Settings
}

HealthcheckedService is a service which provides health check.

type Service

type Service interface {
	// ID is the service id.
	ID(runtime.Runtime) string
	// PreFunc is invoked before a runner is created
	PreFunc(context.Context, runtime.Runtime) error
	// Runner creates runner for the service
	Runner(runtime.Runtime) (runner.Runner, error)
	// PostFunc is invoked after a runner is closed.
	PostFunc(runtime.Runtime, events.ServiceState) error
	// Condition describes the conditions under which a service should
	// start.
	Condition(runtime.Runtime) conditions.Condition
	// DependsOn returns list of service IDs this service depends on.
	DependsOn(runtime.Runtime) []string
}

Service is an interface describing a system service.

type ServiceRunner

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

ServiceRunner wraps the state of the service (running, stopped, ...).

func NewServiceRunner

func NewServiceRunner(instance *singleton, service Service, runtime runtime.Runtime) *ServiceRunner

NewServiceRunner creates new ServiceRunner around Service instance.

func (*ServiceRunner) AsProto

func (svcrunner *ServiceRunner) AsProto() *machineapi.ServiceInfo

AsProto returns protobuf struct with the state of the service runner.

func (*ServiceRunner) GetEventHistory

func (svcrunner *ServiceRunner) GetEventHistory(count int) []events.ServiceEvent

GetEventHistory returns history of events for this service.

func (*ServiceRunner) GetState

func (svcrunner *ServiceRunner) GetState() events.ServiceState

GetState implements events.Recorder.

func (*ServiceRunner) Run

func (svcrunner *ServiceRunner) Run(notifyChannels ...chan<- struct{}) error

Run initializes the service and runs it.

Run returns an error when a service stops.

Run should be run in a goroutine.

func (*ServiceRunner) Shutdown

func (svcrunner *ServiceRunner) Shutdown()

Shutdown initiates shutdown of the service runner

Shutdown completes when Start() returns.

func (*ServiceRunner) Subscribe

func (svcrunner *ServiceRunner) Subscribe(event StateEvent, ch chan<- struct{})

Subscribe to a specific event for this service.

Channel `ch` should be buffered or it should have listener attached to it, as event might be delivered before Subscribe() returns.

func (*ServiceRunner) Unsubscribe

func (svcrunner *ServiceRunner) Unsubscribe(event StateEvent, ch chan<- struct{})

Unsubscribe cancels subscription established with Subscribe.

func (*ServiceRunner) UpdateState

func (svcrunner *ServiceRunner) UpdateState(ctx context.Context, newstate events.ServiceState, message string, args ...interface{})

UpdateState implements events.Recorder.

type StateEvent

type StateEvent string

StateEvent is a service event (e.g. 'up', 'down').

Directories

Path Synopsis
Package runner provides a runner for running services.
Package runner provides a runner for running services.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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