Documentation
¶
Index ¶
- Variables
- type CommandHandler
- type Daemon
- type DaemonLog
- type DaemonOption
- func WithInternalLogger(logger log.Logger) DaemonOption
- func WithInternalLogging(filepath string, level log.Level) DaemonOption
- func WithRPC(cfg RPCConfig) DaemonOption
- func WithReportAlive(timeoutSecs uint64) DaemonOption
- func WithServiceLogger(logger log.Logger) DaemonOption
- func WithSignals(signals ...os.Signal) DaemonOption
- type DaemonService
- type ErrUninitialized
- type Error
- type FilterMode
- type ManagerOption
- type ManagerStateTimeouts
- type NotifyState
- type RPCConfig
- type RPCServer
- type RunContinuousManager
- type Service
- type ServiceAction
- type ServiceContext
- type ServiceFilter
- type ServiceLogger
- type ServiceManager
- type ServiceOption
- type ServiceRunner
- type ServiceStates
- type ServiceWatcher
- type State
- type StateUpdate
- type States
- type StatesResponse
- type SystemNotifier
Constants ¶
This section is empty.
Variables ¶
var NoFilter = ServiceFilter{Mode: None, Names: map[string]struct{}{}}
Functions ¶
This section is empty.
Types ¶
type CommandHandler ¶ added in v1.2.0
type CommandHandler struct {
// contains filtered or unexported fields
}
func (CommandHandler) ChangeLogLevel ¶ added in v1.2.0
func (h CommandHandler) ChangeLogLevel(level log.Level, resp *error) error
type Daemon ¶ added in v1.2.0
type DaemonOption ¶ added in v1.2.0
type DaemonOption func(*daemon)
func WithInternalLogger ¶ added in v1.2.0
func WithInternalLogger(logger log.Logger) DaemonOption
WithInternalLogger sets a custom logger for the daemon to use for internal logging. by default, the daemon will use a noop logger since this logger is used for rxd internals.
func WithInternalLogging ¶ added in v1.2.0
func WithInternalLogging(filepath string, level log.Level) DaemonOption
WithInternalLogging enables the internal logger to write to the filepath using the provided log level.
func WithRPC ¶ added in v1.2.0
func WithRPC(cfg RPCConfig) DaemonOption
WithRPC enables an RPC server to run alongside the daemon. The RPC server will be available at the provided address and port. Currently the RPC server only supports a single method to change log level. An RPC client is provided in the pkg/rxrpc package for external use.
func WithReportAlive ¶ added in v1.2.0
func WithReportAlive(timeoutSecs uint64) DaemonOption
WithReportAlive sets the interval in seconds for when the daemon should report that it is still alive to the service manager. If the value is set to 0, the daemon will not interact with the service manager.
func WithServiceLogger ¶ added in v1.2.0
func WithServiceLogger(logger log.Logger) DaemonOption
func WithSignals ¶ added in v1.2.0
func WithSignals(signals ...os.Signal) DaemonOption
WithSignals sets the OS signals that the daemon should listen for. If no signals are provided, the daemon will listen for SIGINT and SIGTERM by default.
type DaemonService ¶ added in v1.2.0
type DaemonService struct {
Name string
Runner ServiceRunner
}
DaemonService is a struct that contains the Name of the service, the ServiceRunner this struct is what is passed into a Handler for the handler to decide how to interact with the service using the ServiceRunner.
type ErrUninitialized ¶ added in v1.2.0
func (ErrUninitialized) Error ¶ added in v1.2.0
func (e ErrUninitialized) Error() string
type Error ¶
type Error string
const ( ErrDaemonStarted Error = Error("daemon has already been started") ErrDuplicateServiceName Error = Error("duplicate service name found") ErrNoServices Error = Error("no services to run") ErrNoServiceName Error = Error("no service name provided") ErrNilService Error = Error("nil service provided") ErrDuplicateServicePolicy Error = Error("duplicate service policy found") ErrAddingServiceOnceStarted Error = Error("cannot add a service once the daemon is started") )
type FilterMode ¶ added in v1.2.0
type FilterMode int
const ( None FilterMode = iota Include Exclude )
type ManagerOption ¶ added in v1.2.0
type ManagerOption func(m *RunContinuousManager)
func WithInitDelay ¶ added in v1.2.0
func WithInitDelay(delay time.Duration) ManagerOption
func WithTransitionTimeouts ¶ added in v1.2.0
func WithTransitionTimeouts(t ManagerStateTimeouts) ManagerOption
type ManagerStateTimeouts ¶ added in v1.2.0
type NotifyState ¶ added in v1.2.0
type NotifyState uint8
const ( NotifyStateStopped NotifyState = iota NotifyStateStopping NotifyStateRestarting NotifyStateReloading NotifyStateReady NotifyStateAlive )
func (NotifyState) String ¶ added in v1.2.0
func (s NotifyState) String() string
type RPCServer ¶ added in v1.2.0
type RPCServer struct {
// contains filtered or unexported fields
}
func NewRPCHandler ¶ added in v1.2.0
type RunContinuousManager ¶ added in v1.2.0
type RunContinuousManager struct {
DefaultDelay time.Duration
StartupDelay time.Duration
StateTimeouts ManagerStateTimeouts
}
RunContinuousManager is a service handler that does its best to run the service moving the service to the next desired state returned from each lifecycle The handle will override the state transition if the context is cancelled and force the service to Exit.
func NewDefaultManager ¶ added in v1.2.0
func NewDefaultManager(opts ...ManagerOption) RunContinuousManager
func (RunContinuousManager) Manage ¶ added in v1.2.0
func (m RunContinuousManager) Manage(sctx ServiceContext, ds DaemonService, updateState func(string, State))
RunContinuousManager runs the service continuously until the context is cancelled. service contains the service runner that will be executed. which is then handled by the daemon.
type Service ¶
type Service struct {
Name string
Runner ServiceRunner
Manager ServiceManager
}
Service is a struct that contains the Name of the service, the ServiceRunner and the ServiceHandler. This struct is what the caller uses to add a new service to the daemon. The daemon performs checks and translates this struct into a Service struct before starting it.
func NewService ¶
func NewService(name string, runner ServiceRunner, opts ...ServiceOption) Service
type ServiceAction ¶ added in v1.2.0
type ServiceAction uint8
const ( Entering ServiceAction = iota Exiting Changing )
func (ServiceAction) String ¶ added in v1.2.0
func (s ServiceAction) String() string
type ServiceContext ¶
type ServiceContext interface {
context.Context
ServiceWatcher
ServiceLogger
Name() string
// With returns a new ServiceContext with the given fields appended to the existing fields.
WithFields(fields ...log.Field) ServiceContext
WithParent(ctx context.Context) (ServiceContext, context.CancelFunc)
WithName(name string) (ServiceContext, context.CancelFunc)
}
type ServiceFilter ¶ added in v1.2.0
type ServiceFilter struct {
Mode FilterMode
Names map[string]struct{}
}
func NewServiceFilter ¶ added in v1.2.0
func NewServiceFilter(mode FilterMode, names ...string) ServiceFilter
type ServiceLogger ¶ added in v1.2.0
type ServiceManager ¶ added in v1.2.0
type ServiceManager interface {
Manage(ctx ServiceContext, dService DaemonService, updateState func(service string, state State))
}
ServiceManager interface defines the methods that a service handler must implement
type ServiceOption ¶
type ServiceOption func(*Service)
func WithManager ¶ added in v1.2.0
func WithManager(manager ServiceManager) ServiceOption
type ServiceRunner ¶ added in v1.2.0
type ServiceRunner interface {
Init(ServiceContext) error
Idle(ServiceContext) error
Run(ServiceContext) error
Stop(ServiceContext) error
}
type ServiceStates ¶ added in v1.2.0
type ServiceWatcher ¶ added in v1.2.0
type ServiceWatcher interface {
WatchAllStates(ServiceFilter) (<-chan ServiceStates, context.CancelFunc)
WatchAnyServices(action ServiceAction, target State, services ...string) (<-chan ServiceStates, context.CancelFunc)
WatchAllServices(action ServiceAction, target State, services ...string) (<-chan ServiceStates, context.CancelFunc)
}
type StateUpdate ¶ added in v1.0.0
StateUpdate reflects any given update of lifecycle state at a given time.
type States ¶ added in v1.0.0
States is a map of service name to service state which reflects the service name and its lifecycle state.
type StatesResponse ¶ added in v1.2.0
type StatesResponse struct {
States ServiceStates
Err error
}
type SystemNotifier ¶ added in v1.2.0
type SystemNotifier interface {
Start(ctx context.Context, logger log.Logger) error
Notify(state NotifyState) error
}
func NewSystemdNotifier ¶ added in v1.2.0
func NewSystemdNotifier(socketName string, durationSecs uint64) (SystemNotifier, error)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
multi_service
command
|
|
|
multi_service_rpc
command
|
|
|
multi_service_rpc/rpc_client
command
|
|
|
pubsub
command
|
|
|
single_service
command
|
|
|
single_service_custom_manager
command
|
|
|
pkg
|
|