Documentation ¶
Overview ¶
Package service builds on github.com/kardianos/service to run sidecars as OS services/daemons
Index ¶
- Constants
- func AsExitStatus(err error) (int, error)
- func CmdName() string
- func WithService(ctx context.Context, svc *Service) context.Context
- type Config
- func (cfg *Config) GetBoolOption(name string, defaultValue bool) bool
- func (cfg *Config) GetEnv(name, defaultValue string) string
- func (cfg *Config) GetOption(name string) (any, bool)
- func (cfg *Config) GetStringOption(name, defaultValue string) string
- func (cfg *Config) SetBoolOption(name string, value bool)
- func (cfg *Config) SetDefaults()
- func (cfg *Config) SetEnv(name, value string)
- func (cfg *Config) SetOption(name string, value any)
- func (cfg *Config) SetStringOption(name, value string)
- type ErrorExitCode
- type Service
- func (s *Service) AddCommand(cmd *cobra.Command)
- func (s *Service) Cancelled() <-chan struct{}
- func (s *Service) Command() *cobra.Command
- func (s *Service) Done() <-chan struct{}
- func (s *Service) Err() error
- func (s *Service) Execute() error
- func (s *Service) ExecuteContext(ctx context.Context) error
- func (s *Service) Interactive() bool
- func (s *Service) NewContext(ctx context.Context) (context.Context, error)
- func (s *Service) PersistentFlags() *pflag.FlagSet
- func (s *Service) Platform() string
- func (s *Service) SystemLogger() slog.Logger
- func (s *Service) Wait() error
Constants ¶
const ( ExitStatusOK int = iota // ExitStatusOK indicates everything is fine ExitStatusMinor // ExitStatusMinor indicates there was a minor problem ExitStatusMajor // ExitStatusMajor indicates there was a major problem )
Variables ¶
This section is empty.
Functions ¶
func AsExitStatus ¶
AsExitStatus looks at an Execute() error and decides how the process should finish
Types ¶
type Config ¶
type Config struct { service.Config // SanityDelay indicates how long we wait for // the run command to fail before claiming a // successful start SanityDelay time.Duration `default:"2s"` }
Config describes the Service we are assembling
func (*Config) GetBoolOption ¶ added in v0.1.0
GetBoolOption gets a boolean option from the service.Config's KeyValue store.
func (*Config) GetEnv ¶ added in v0.1.0
GetEnv gets an environment variable from the service.Config.
func (*Config) GetOption ¶ added in v0.1.0
GetOption gets an arbitrary option from the service.Config's KeyValue store.
func (*Config) GetStringOption ¶ added in v0.1.0
GetStringOption gets a string option from the service.Config's KeyValue store.
func (*Config) SetBoolOption ¶ added in v0.1.0
SetBoolOption sets a boolean option to the service.Config's KeyValue store.
func (*Config) SetEnv ¶ added in v0.1.0
SetEnv sets an environment variable on the service.Config.
func (*Config) SetOption ¶ added in v0.1.0
SetOption sets an arbitrary option on the service.Config's KeyValue store.
func (*Config) SetStringOption ¶ added in v0.1.0
SetStringOption sets a string option to the service.Config's KeyValue store.
type ErrorExitCode ¶
ErrorExitCode is an error wrapper that knows how the application should exit
func (ErrorExitCode) Error ¶
func (e ErrorExitCode) Error() string
func (ErrorExitCode) ExitStatus ¶
func (e ErrorExitCode) ExitStatus() int
ExitStatus tells the code for os.Exit()
func (ErrorExitCode) Unwrap ¶
func (e ErrorExitCode) Unwrap() error
type Service ¶
type Service struct { Config Config // contains filtered or unexported fields }
Service is an application that runs supervised by the OS
func Build ¶ added in v0.1.0
Build creates a new service from a given root and serve cobra.Command. service.Config parameters can be modified until Execute is called or via PersistentPreRunE on the root command.
func GetService ¶ added in v0.1.0
GetService gets the current Service from the context.
func MustBuild ¶ added in v0.1.0
MustBuild creates a new service from a given root and serve cobra.Command, and panics if there is a problem.
func (*Service) AddCommand ¶
AddCommand adds an extra interactive command to the tool
func (*Service) Cancelled ¶ added in v0.1.0
func (s *Service) Cancelled() <-chan struct{}
Cancelled returns a channel that is closed when shutdown has been initiated.
func (*Service) Command ¶
Command returns the root cobra.Command
func (*Service) Done ¶ added in v0.1.0
func (s *Service) Done() <-chan struct{}
Done returns a channel that is closed when the worker has finished.
func (*Service) ExecuteContext ¶ added in v0.1.0
ExecuteContext either runs via cobra or the service invoked process
func (*Service) Interactive ¶ added in v0.1.0
Interactive returns false if running under the OS service manager and true otherwise.
func (*Service) NewContext ¶ added in v0.1.0
NewContext prepares a context for cmd.ExecuteContext() or cmd.SetContext()
func (*Service) PersistentFlags ¶
PersistentFlags returns the flags also passed to sub-commands
func (*Service) SystemLogger ¶ added in v0.1.0
SystemLogger returns the OS system logger. Entries will be recorded JSON encoded.