Adds public ReloadOptions api support

Refactor Reload to call ReloadOptions
This commit is contained in:
2021-07-04 13:59:14 -07:00
parent 54e16e80c5
commit 0e04effaed

View File

@@ -701,11 +701,30 @@ func (s *Server) recheckPinnedCerts(curOpts *Options, newOpts *Options) {
}
}
// Reload reads the current configuration file and applies any supported
// changes. This returns an error if the server was not started with a config
// file or an option which doesn't support hot-swapping was changed.
// Reload reads the current configuration file and calls out to ReloadOptions
// to apply the changes. This returns an error if the server was not started
// with a config file or an option which doesn't support hot-swapping was changed.
func (s *Server) Reload() error {
s.mu.Lock()
configFile := s.configFile
s.mu.Unlock()
if configFile == "" {
return errors.New("can only reload config when a file is provided using -c or --config")
}
newOpts, err := ProcessConfigFile(configFile)
if err != nil {
// TODO: Dump previous good config to a .bak file?
return err
}
return s.ReloadOptions(newOpts)
}
// ReloadOptions applies any supported options from the provided Option
// type. This returns an error if an option which doesn't support
// hot-swapping was changed.
func (s *Server) ReloadOptions(newOpts *Options) error {
s.mu.Lock()
s.reloading = true
defer func() {
@@ -714,18 +733,6 @@ func (s *Server) Reload() error {
s.mu.Unlock()
}()
if s.configFile == "" {
s.mu.Unlock()
return errors.New("can only reload config when a file is provided using -c or --config")
}
newOpts, err := ProcessConfigFile(s.configFile)
if err != nil {
s.mu.Unlock()
// TODO: Dump previous good config to a .bak file?
return err
}
curOpts := s.getOpts()
// Wipe trusted keys if needed when we have an operator.
@@ -787,7 +794,6 @@ func (s *Server) Reload() error {
s.mu.Unlock()
return nil
}
func applyBoolFlags(newOpts, flagOpts *Options) {
// Reset fields that may have been set to `true` in
// MergeOptions() when some of the flags default to `true`