Files
kairos-agent/internal/agent/agent_options.go
Ettore Di Giacinto f185430669 art: Allow the agent to self-restart on error
In init systems that don't support automatic restart this might be handy when we fail because we boot up too fast.

This is an attempt to fix https://github.com/c3os-io/c3os/issues/47
2022-08-08 08:15:15 +00:00

51 lines
994 B
Go

package agent
// Options yields the options for the running agent
type Options struct {
ApiAddress string
Dir []string
Force bool
Restart bool
}
// Apply applies option to the options struct
func (o *Options) Apply(opts ...Option) error {
for _, oo := range opts {
if err := oo(o); err != nil {
return err
}
}
return nil
}
// Option is a generic option for the Agent
type Option func(o *Options) error
// ForceAgent forces the agent to run
var ForceAgent Option = func(o *Options) error {
o.Force = true
return nil
}
// RestartAgent makes the agent restart on error
var RestartAgent Option = func(o *Options) error {
o.Restart = true
return nil
}
// WithAPI sets the API address
func WithAPI(address string) Option {
return func(o *Options) error {
o.ApiAddress = address
return nil
}
}
// WithDirectory sets the Agent config directories
func WithDirectory(dirs ...string) Option {
return func(o *Options) error {
o.Dir = dirs
return nil
}
}