Documentation ¶
Index ¶
- Variables
- type CommandHandler
- type Daemon
- type DaemonLog
- type DaemonOption
- func WithCustomPrestartPipeline(prestart Pipeline) DaemonOption
- func WithInternalLogger(logger log.Logger) DaemonOption
- func WithInternalLogging(filepath string, level log.Level) DaemonOption
- func WithLogWorkerCount(count int) DaemonOption
- func WithPrestart(conf PrestartConfig, stages ...Stage) 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 Pipeline
- type PrestartConfig
- type RPCConfig
- type RPCServer
- type RunContinuousManager
- type RunUntilSuccessManager
- type Service
- type ServiceAction
- type ServiceContext
- type ServiceFilter
- type ServiceLogger
- type ServiceManager
- type ServiceOption
- type ServiceRunner
- type ServiceStates
- type ServiceWatcher
- type Stage
- type StageFunc
- 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 Daemon interface { AddServices(services ...Service) error AddService(service Service) error Start(ctx context.Context) error }
func NewDaemon ¶
func NewDaemon(name string, options ...DaemonOption) Daemon
NewDaemon creates and return an instance of the reactive daemon NOTE: The service logger runs with a default stdout logger. This can be optionally changed by passing the WithServiceLogger option in NewDaemon The internal logger is disabled by default and can be enabled by passing the WithInternalLogger option in NewDaemon
func NewDaemonWithLogger ¶ added in v1.2.1
func NewDaemonWithLogger(name string, logger log.Logger, options ...DaemonOption) Daemon
NewDaemonWithLogger creates and return an instance of the reactive daemon with a custom service logger NOTE: this can also be set by passing the WithServiceLogger option in NewDaemon This is to support the old pattern of creating a daemon with a custom service logger.
type DaemonOption ¶ added in v1.2.0
type DaemonOption func(*daemon)
func WithCustomPrestartPipeline ¶ added in v1.2.1
func WithCustomPrestartPipeline(prestart Pipeline) DaemonOption
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 WithLogWorkerCount ¶ added in v1.2.1
func WithLogWorkerCount(count int) DaemonOption
func WithPrestart ¶ added in v1.2.1
func WithPrestart(conf PrestartConfig, stages ...Stage) DaemonOption
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 Pipeline ¶ added in v1.2.1
func NewPrestartPipeline ¶ added in v1.2.1
func NewPrestartPipeline(conf PrestartConfig, stages ...Stage) Pipeline
type PrestartConfig ¶ added in v1.2.1
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, updateC chan<- StateUpdate)
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 RunUntilSuccessManager ¶ added in v1.2.1
func NewRunUntilSuccessManager ¶ added in v1.2.1
func NewRunUntilSuccessManager(defaultDelay, startupDelay time.Duration) RunUntilSuccessManager
NewRunUntilSuccessManager creates a new RunUntilSuccessManager with the provided startup delay. RunUntilSuccessManager will continue to try to run the service lifecycles until the service exits Run with nil error.
func (RunUntilSuccessManager) Manage ¶ added in v1.2.1
func (m RunUntilSuccessManager) Manage(sctx ServiceContext, ds DaemonService, updateC chan<- StateUpdate)
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 ( Entered ServiceAction = iota Exited Changed // Deprecated: In favor of using Entered Entering // Deprecated: In favor of using Exited Exiting // Deprecated: In favor of using Changed Changing NotIn // used for inverse matching of states )
func (ServiceAction) String ¶ added in v1.2.0
func (s ServiceAction) String() string
type ServiceContext ¶
type ServiceContext interface { context.Context ServiceWatcher ServiceLogger Name() string 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, updateC chan<- StateUpdate)
}
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
For this example we will create two services that will run until they are stopped.
|
For this example we will create two services that will run until they are stopped. |
single_service
For this example we will create a simple API service that will run until it is stopped either via the context timeout (30s) or an OS signal (SIGINT, SIGTERM).
|
For this example we will create a simple API service that will run until it is stopped either via the context timeout (30s) or an OS signal (SIGINT, SIGTERM). |
pkg
|
|