Documentation
¶
Overview ¶
Package glcm manage life cycle multiple go routines.
Package glcm is a generated GoMock package.
Index ¶
- Constants
- Variables
- type AutoRestart
- type AutoRestartOptions
- type Hook
- type MockHook
- type MockHookMockRecorder
- type MockRunner
- func (m *MockRunner) BootUp() error
- func (m *MockRunner) DeregisterService(arg0 string) error
- func (m *MockRunner) EXPECT() *MockRunnerMockRecorder
- func (m *MockRunner) IsRunning() bool
- func (m *MockRunner) RegisterService(arg0 Service, arg1 ServiceOptions) error
- func (m *MockRunner) RestartAllServices()
- func (m *MockRunner) RestartService(arg0 ...string) error
- func (m *MockRunner) Shutdown()
- func (m *MockRunner) Status() *RunnerStatus
- func (m *MockRunner) StopAllServices()
- func (m *MockRunner) StopService(arg0 ...string) error
- type MockRunnerMockRecorder
- func (mr *MockRunnerMockRecorder) BootUp() *gomock.Call
- func (mr *MockRunnerMockRecorder) DeregisterService(arg0 interface{}) *gomock.Call
- func (mr *MockRunnerMockRecorder) IsRunning() *gomock.Call
- func (mr *MockRunnerMockRecorder) RegisterService(arg0, arg1 interface{}) *gomock.Call
- func (mr *MockRunnerMockRecorder) RestartAllServices() *gomock.Call
- func (mr *MockRunnerMockRecorder) RestartService(arg0 ...interface{}) *gomock.Call
- func (mr *MockRunnerMockRecorder) Shutdown() *gomock.Call
- func (mr *MockRunnerMockRecorder) Status() *gomock.Call
- func (mr *MockRunnerMockRecorder) StopAllServices() *gomock.Call
- func (mr *MockRunnerMockRecorder) StopService(arg0 ...interface{}) *gomock.Call
- type MockService
- type MockServiceMockRecorder
- type MockTerminator
- type MockTerminatorMockRecorder
- type MockWrapper
- func (m *MockWrapper) AutoRestart() *AutoRestart
- func (m *MockWrapper) EXPECT() *MockWrapperMockRecorder
- func (m *MockWrapper) Name() string
- func (m *MockWrapper) Start()
- func (m *MockWrapper) Status() ServiceStatus
- func (m *MockWrapper) Stop()
- func (m *MockWrapper) TermCh() chan struct{}
- func (m *MockWrapper) Uptime() time.Duration
- type MockWrapperMockRecorder
- func (mr *MockWrapperMockRecorder) AutoRestart() *gomock.Call
- func (mr *MockWrapperMockRecorder) Name() *gomock.Call
- func (mr *MockWrapperMockRecorder) Start() *gomock.Call
- func (mr *MockWrapperMockRecorder) Status() *gomock.Call
- func (mr *MockWrapperMockRecorder) Stop() *gomock.Call
- func (mr *MockWrapperMockRecorder) TermCh() *gomock.Call
- func (mr *MockWrapperMockRecorder) Uptime() *gomock.Call
- type Runner
- type RunnerOptions
- type RunnerStatus
- type SchedulingOptions
- type Service
- type ServiceInfo
- type ServiceOptions
- type ServiceStatus
- type SocketResponse
- type Terminator
- type Wrapper
Constants ¶
const ( SocketActionStopAllServices socketAction = "stopAll" SocketActionStopService socketAction = "stop" SocketActionRestartAll socketAction = "restartAll" SocketActionRestartService socketAction = "restart" SocketActionStatus socketAction = "status" )
list of supported socket action commands
const ( Success socketCommandStatus = "success" Failure socketCommandStatus = "failure" )
list of supported socket command status
Variables ¶
var ( ErrRegisterServiceAlreadyExists = errors.New("service already exists") ErrDeregisterServiceNotFound = errors.New("service not found") ErrRunnerAlreadyRunning = errors.New("runner already running") ErrRegisterNilService = errors.New("can not register nil service") ErrUnsupportedOS = errors.New("unsupported OS") ErrSocketNoService = errors.New("no service provided") )
var (
ErrServiceNotRunning = errors.New("service not running")
)
Functions ¶
This section is empty.
Types ¶
type AutoRestart ¶
type AutoRestart struct {
Enabled bool // flag to indicate if auto-restart is enabled.
MaxRetries int // maximum number of retries.
Backoff bool // flag to indicate if backoff is enabled.
BackoffExponent int // exponent for the backoff.
RetryCount int // current number of retries for the service.
PendingStart atomic.Bool // flag to indicate if the service is pending for a start after the backoff.
}
AutoRestart is the configuration set for auto-restart.
type AutoRestartOptions ¶
type AutoRestartOptions struct {
// Enabled represents if the auto-restart is enabled.
Enabled bool
// MaxRetries represents the maximum number of retries.
MaxRetries int
// Backoff represents if the backoff is enabled.
Backoff bool
// BackOffExponent represents the exponent for the backoff.
BackOffExponent int
}
AutoRestartOptions represents the options for auto-restarting the service.
type Hook ¶
type Hook interface {
// Execute executes the hook method.
Execute() error
// Name returns the name of the hook.
Name() string
}
Hook is an interface which represents a single hook. When a servcice is regsited in the runner, implementations of the Hndler interface can be registered too. Based on the nature of the hook (pre-run or post-run), the hook will be executed.
type MockHook ¶
type MockHook struct {
// contains filtered or unexported fields
}
MockHook is a mock of Hook interface.
func NewMockHook ¶
func NewMockHook(ctrl *gomock.Controller) *MockHook
NewMockHook creates a new mock instance.
func (*MockHook) EXPECT ¶
func (m *MockHook) EXPECT() *MockHookMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockHookMockRecorder ¶
type MockHookMockRecorder struct {
// contains filtered or unexported fields
}
MockHookMockRecorder is the mock recorder for MockHook.
func (*MockHookMockRecorder) Execute ¶
func (mr *MockHookMockRecorder) Execute() *gomock.Call
Execute indicates an expected call of Execute.
func (*MockHookMockRecorder) Name ¶
func (mr *MockHookMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
type MockRunner ¶
type MockRunner struct {
// contains filtered or unexported fields
}
MockRunner is a mock of Runner interface.
func NewMockRunner ¶
func NewMockRunner(ctrl *gomock.Controller) *MockRunner
NewMockRunner creates a new mock instance.
func (*MockRunner) DeregisterService ¶
func (m *MockRunner) DeregisterService(arg0 string) error
DeregisterService mocks base method.
func (*MockRunner) EXPECT ¶
func (m *MockRunner) EXPECT() *MockRunnerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockRunner) RegisterService ¶
func (m *MockRunner) RegisterService(arg0 Service, arg1 ServiceOptions) error
RegisterService mocks base method.
func (*MockRunner) RestartAllServices ¶
func (m *MockRunner) RestartAllServices()
RestartAllServices mocks base method.
func (*MockRunner) RestartService ¶
func (m *MockRunner) RestartService(arg0 ...string) error
RestartService mocks base method.
func (*MockRunner) StopAllServices ¶
func (m *MockRunner) StopAllServices()
StopAllServices mocks base method.
func (*MockRunner) StopService ¶
func (m *MockRunner) StopService(arg0 ...string) error
StopService mocks base method.
type MockRunnerMockRecorder ¶
type MockRunnerMockRecorder struct {
// contains filtered or unexported fields
}
MockRunnerMockRecorder is the mock recorder for MockRunner.
func (*MockRunnerMockRecorder) BootUp ¶
func (mr *MockRunnerMockRecorder) BootUp() *gomock.Call
BootUp indicates an expected call of BootUp.
func (*MockRunnerMockRecorder) DeregisterService ¶
func (mr *MockRunnerMockRecorder) DeregisterService(arg0 interface{}) *gomock.Call
DeregisterService indicates an expected call of DeregisterService.
func (*MockRunnerMockRecorder) IsRunning ¶
func (mr *MockRunnerMockRecorder) IsRunning() *gomock.Call
IsRunning indicates an expected call of IsRunning.
func (*MockRunnerMockRecorder) RegisterService ¶
func (mr *MockRunnerMockRecorder) RegisterService(arg0, arg1 interface{}) *gomock.Call
RegisterService indicates an expected call of RegisterService.
func (*MockRunnerMockRecorder) RestartAllServices ¶
func (mr *MockRunnerMockRecorder) RestartAllServices() *gomock.Call
RestartAllServices indicates an expected call of RestartAllServices.
func (*MockRunnerMockRecorder) RestartService ¶
func (mr *MockRunnerMockRecorder) RestartService(arg0 ...interface{}) *gomock.Call
RestartService indicates an expected call of RestartService.
func (*MockRunnerMockRecorder) Shutdown ¶
func (mr *MockRunnerMockRecorder) Shutdown() *gomock.Call
Shutdown indicates an expected call of Shutdown.
func (*MockRunnerMockRecorder) Status ¶
func (mr *MockRunnerMockRecorder) Status() *gomock.Call
Status indicates an expected call of Status.
func (*MockRunnerMockRecorder) StopAllServices ¶
func (mr *MockRunnerMockRecorder) StopAllServices() *gomock.Call
StopAllServices indicates an expected call of StopAllServices.
func (*MockRunnerMockRecorder) StopService ¶
func (mr *MockRunnerMockRecorder) StopService(arg0 ...interface{}) *gomock.Call
StopService indicates an expected call of StopService.
type MockService ¶
type MockService struct {
// contains filtered or unexported fields
}
MockService is a mock of Service interface.
func NewMockService ¶
func NewMockService(ctrl *gomock.Controller) *MockService
NewMockService creates a new mock instance.
func (*MockService) EXPECT ¶
func (m *MockService) EXPECT() *MockServiceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockServiceMockRecorder ¶
type MockServiceMockRecorder struct {
// contains filtered or unexported fields
}
MockServiceMockRecorder is the mock recorder for MockService.
func (*MockServiceMockRecorder) Name ¶
func (mr *MockServiceMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
func (*MockServiceMockRecorder) Start ¶
func (mr *MockServiceMockRecorder) Start(arg0 interface{}) *gomock.Call
Start indicates an expected call of Start.
type MockTerminator ¶
type MockTerminator struct {
// contains filtered or unexported fields
}
MockTerminator is a mock of Terminator interface.
func NewMockTerminator ¶
func NewMockTerminator(ctrl *gomock.Controller) *MockTerminator
NewMockTerminator creates a new mock instance.
func (*MockTerminator) EXPECT ¶
func (m *MockTerminator) EXPECT() *MockTerminatorMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockTerminator) TermCh ¶
func (m *MockTerminator) TermCh() chan struct{}
TermCh mocks base method.
type MockTerminatorMockRecorder ¶
type MockTerminatorMockRecorder struct {
// contains filtered or unexported fields
}
MockTerminatorMockRecorder is the mock recorder for MockTerminator.
func (*MockTerminatorMockRecorder) TermCh ¶
func (mr *MockTerminatorMockRecorder) TermCh() *gomock.Call
TermCh indicates an expected call of TermCh.
type MockWrapper ¶
type MockWrapper struct {
// contains filtered or unexported fields
}
MockWrapper is a mock of Wrapper interface.
func NewMockWrapper ¶
func NewMockWrapper(ctrl *gomock.Controller) *MockWrapper
NewMockWrapper creates a new mock instance.
func (*MockWrapper) AutoRestart ¶
func (m *MockWrapper) AutoRestart() *AutoRestart
AutoRestart mocks base method.
func (*MockWrapper) EXPECT ¶
func (m *MockWrapper) EXPECT() *MockWrapperMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockWrapperMockRecorder ¶
type MockWrapperMockRecorder struct {
// contains filtered or unexported fields
}
MockWrapperMockRecorder is the mock recorder for MockWrapper.
func (*MockWrapperMockRecorder) AutoRestart ¶
func (mr *MockWrapperMockRecorder) AutoRestart() *gomock.Call
AutoRestart indicates an expected call of AutoRestart.
func (*MockWrapperMockRecorder) Name ¶
func (mr *MockWrapperMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
func (*MockWrapperMockRecorder) Start ¶
func (mr *MockWrapperMockRecorder) Start() *gomock.Call
Start indicates an expected call of Start.
func (*MockWrapperMockRecorder) Status ¶
func (mr *MockWrapperMockRecorder) Status() *gomock.Call
Status indicates an expected call of Status.
func (*MockWrapperMockRecorder) Stop ¶
func (mr *MockWrapperMockRecorder) Stop() *gomock.Call
Stop indicates an expected call of Stop.
func (*MockWrapperMockRecorder) TermCh ¶
func (mr *MockWrapperMockRecorder) TermCh() *gomock.Call
TermCh indicates an expected call of TermCh.
func (*MockWrapperMockRecorder) Uptime ¶
func (mr *MockWrapperMockRecorder) Uptime() *gomock.Call
Uptime indicates an expected call of Uptime.
type Runner ¶
type Runner interface {
// IsRunning returns true if the runner is running, otherwise false.
IsRunning() bool
// RegisterService registers a service with the runner.
RegisterService(Service, ServiceOptions) error
// DeregisterService deregisters a service from the runner.
DeregisterService(string) error
// Shutdown stops all the services and the runner.
Shutdown()
// StopAllServices stops all the services.
StopAllServices()
// StopService stops the specified services.
StopService(...string) error
// RestartService restarts the specified services.
RestartService(...string) error
// RestartAllServices restarts all the services.
RestartAllServices()
// BootUp starts the runner.
BootUp() error
// Status returns the status of the runner along with the status of each registered service.
Status() *RunnerStatus
}
Runner represents the interface for the base runner methods.
type RunnerOptions ¶
type RunnerOptions struct {
// HideBanner represents if the banner should be hidden.
HideBanner bool
// Verbose represents if the logs should be suppressed or not.
Verbose bool
// Socket represents if the socket should be enabled or not.
Socket bool
// SocketPath represents the path to the socket file.
SocketPath string
// AllowedUID represents the allowed user ids to interact with the socket.
AllowedUID []int
// ShutdownTimeout represents the timeout for shutting down the runner.
ShutdownTimeout time.Duration
}
RunnerOptions represents the options for the runner.
func (*RunnerOptions) Sanitize ¶
func (r *RunnerOptions) Sanitize()
Santizie fills the default values for the runner options.
type RunnerStatus ¶
type RunnerStatus struct {
IsRunning bool `json:"isRunning"`
Services map[string]ServiceInfo `json:"services"`
}
RunnerStatus represents the status of the runner.
type SchedulingOptions ¶
type SchedulingOptions struct {
// Enabled represents if the auto-restart is enabled.
Enabled bool
// Cron represents the cron expression for scheduling the service.
Cron string
// TimeOut represents the timeout for the service.
// After the timeout, the service will be sent a termination signal.
TimeOut time.Duration
// MaxRuns represents the maximum number of runs for the service.
MaxRuns int
}
SchedulingOptions represents the options for scheduling the service.
type Service ¶
type Service interface {
// Name returns the name of the service.
Name() string
// Start executes/boots-up/starts a service.
Start(Terminator)
}
Service defines an interface which represents a single service and the operations that can be performed on the service. Note: The service should be able to handle the termination signal. At this point, I don't think we need to have a Stop or Restart method. Once the termincation channel is closed, the service should stop. If the service needs to be restarted, the runner will take care of it, internally.
type ServiceInfo ¶
type ServiceInfo struct {
Status ServiceStatus `json:"status"`
Uptime time.Duration `json:"uptime"`
Restarts int `json:"restarts"`
}
ServiceStatus represents the available information of the service.
type ServiceOptions ¶
type ServiceOptions struct {
// PreHooks are the hooks that are executed before the service is started.
PreHooks []Hook
// PostHooks are the hooks that are executed after the service is stopped.
PostHooks []Hook
// AutoStart represents the options for auto-starting the service.
AutoStart AutoRestartOptions
// Schedule represents the options for scheduling the service.
Schedule SchedulingOptions
}
ServiceOptions represents the options for a service.
func (*ServiceOptions) Sanitize ¶
func (s *ServiceOptions) Sanitize()
Sanitize fills the default values for the service options.
type ServiceStatus ¶
type ServiceStatus string
ServiceStatus represents the status of the service.
const ( ServiceStatusRegistered ServiceStatus = "registered" ServiceStatusRunning ServiceStatus = "running" ServiceStatusExited ServiceStatus = "exited" ServiceStatusStopped ServiceStatus = "stopped" ServiceStatusScheduled ServiceStatus = "scheduled" ServiceStatusScheduledForRestart ServiceStatus = "scheduled-for-restart" ServiceStatusExhausted ServiceStatus = "exhausted" )
Status options for the service.
type SocketResponse ¶
type SocketResponse struct {
Result interface{} `json:"result"`
Status socketCommandStatus `json:"status"`
}
SocketResponse represents the response from the socket.
type Terminator ¶
type Terminator interface {
// TermCh returns a channel which will be closed when the service should stop.
TermCh() chan struct{}
}
Terminator defines an indicator to the service to stop.
type Wrapper ¶
type Wrapper interface {
// Name returns the name of the service.
Name() string
// Status returns the status of the service/wrapper.
Status() ServiceStatus
// TermCh returns the termination channel for the service.
TermCh() chan struct{}
// Start starts the services in the wrapper.
Start()
// Stop stops the service in the wrapper and waits for the service to stop.
Stop()
// AutoRestart returns the auto-restart configuration for the wrapper.
AutoRestart() *AutoRestart
// Uptime returns the uptime of the service.
Uptime() time.Duration
}
Wrapper is an interface which represents the wraper around the service.
func NewWrapper ¶
func NewWrapper(s Service, wg *sync.WaitGroup, opts ServiceOptions) Wrapper
NewWrapper returns a new instance of the service Wrapper.