mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-17 07:17:41 +00:00
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
51 lines
994 B
Go
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
|
|
}
|
|
}
|