Documentation ¶
Index ¶
- Constants
- Variables
- func Services(runtime runtime.Runtime) *singleton
- func WaitForService(event StateEvent, service string) conditions.Condition
- type APIRestartableService
- type APIStartableService
- type APIStoppableService
- type HealthcheckedService
- type Service
- type ServiceRunner
- func (svcrunner *ServiceRunner) AsProto() *machineapi.ServiceInfo
- func (svcrunner *ServiceRunner) GetEventHistory(count int) []events.ServiceEvent
- func (svcrunner *ServiceRunner) GetState() events.ServiceState
- func (svcrunner *ServiceRunner) Run() error
- func (svcrunner *ServiceRunner) Shutdown()
- func (svcrunner *ServiceRunner) Subscribe(event StateEvent, ch chan<- struct{})
- func (svcrunner *ServiceRunner) Unsubscribe(event StateEvent, ch chan<- struct{})
- func (svcrunner *ServiceRunner) UpdateState(ctx context.Context, newstate events.ServiceState, message string, ...)
- type StateEvent
Constants ¶
const ( StateEventUp = StateEvent("up") StateEventDown = StateEvent("down") StateEventFinished = StateEvent("finished") )
Service event list.
Variables ¶
var ErrSkip = errors.New("service skipped")
ErrSkip is returned by Run when service is skipped.
var WaitConditionCheckInterval = time.Second
WaitConditionCheckInterval is time between checking for wait condition description changes.
Exposed here for unit-tests to override.
Functions ¶
func WaitForService ¶
func WaitForService(event StateEvent, service string) conditions.Condition
WaitForService waits for service to reach some state event.
Types ¶
type APIRestartableService ¶
APIRestartableService is a service which allows to be restarted via API.
type APIStartableService ¶
APIStartableService is a service which allows to be started via API.
type APIStoppableService ¶
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(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 ¶ added in v1.3.3
func (svcrunner *ServiceRunner) Run() 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.