diff options
-rw-r--r-- | cmd/gobgpd/main.go | 36 | ||||
-rw-r--r-- | internal/pkg/config/serve.go | 42 | ||||
-rw-r--r-- | pkg/config/config.go | 6 |
3 files changed, 30 insertions, 54 deletions
diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go index 794d6e10..1bdcb449 100644 --- a/cmd/gobgpd/main.go +++ b/cmd/gobgpd/main.go @@ -168,17 +168,41 @@ func main() { return } - configCh := config.ReadConfigFileOnSighup(opts.ConfigFile, opts.ConfigType) + signal.Notify(sigCh, syscall.SIGHUP) loop := func() { - initialConfig := <-configCh + initialConfig, err := config.ReadConfigFile(opts.ConfigFile, opts.ConfigType) + if err != nil { + log.WithFields(log.Fields{ + "Topic": "Config", + "Error": err, + }).Fatalf("Can't read config file %s", opts.ConfigFile) + } + log.WithFields(log.Fields{ + "Topic": "Config", + }).Info("Finished reading the config file") + c := config.ApplyInitialConfig(bgpServer, initialConfig, opts.GracefulRestart) for { select { - case <-sigCh: - stopServer(bgpServer, opts.UseSdNotify) - return - case newConfig := <-configCh: + case sig := <-sigCh: + if sig != syscall.SIGHUP { + stopServer(bgpServer, opts.UseSdNotify) + return + } + + log.WithFields(log.Fields{ + "Topic": "Config", + }).Info("Reload the config file") + newConfig, err := config.ReadConfigFile(opts.ConfigFile, opts.ConfigType) + if err != nil { + log.WithFields(log.Fields{ + "Topic": "Config", + "Error": err, + }).Warningf("Can't read config file %s", opts.ConfigFile) + continue + } + c = config.UpdateConfig(bgpServer, c, newConfig) } } diff --git a/internal/pkg/config/serve.go b/internal/pkg/config/serve.go index c1525525..1fe71332 100644 --- a/internal/pkg/config/serve.go +++ b/internal/pkg/config/serve.go @@ -1,10 +1,6 @@ package config import ( - "os" - "os/signal" - "syscall" - log "github.com/sirupsen/logrus" "github.com/spf13/viper" ) @@ -45,44 +41,6 @@ func ReadConfigfile(path, format string) (*BgpConfigSet, error) { return config, nil } -func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) { - sigCh := make(chan os.Signal, 1) - signal.Notify(sigCh, syscall.SIGHUP) - - cnt := 0 - for { - c, err := ReadConfigfile(path, format) - if err != nil { - goto ERROR - } - if cnt == 0 { - log.WithFields(log.Fields{ - "Topic": "Config", - }).Info("Finished reading the config file") - } - cnt++ - configCh <- c - goto NEXT - ERROR: - if cnt == 0 { - log.WithFields(log.Fields{ - "Topic": "Config", - "Error": err, - }).Fatalf("Can't read config file %s", path) - } else { - log.WithFields(log.Fields{ - "Topic": "Config", - "Error": err, - }).Warningf("Can't read config file %s", path) - } - NEXT: - <-sigCh - log.WithFields(log.Fields{ - "Topic": "Config", - }).Info("Reload the config file") - } -} - func ConfigSetToRoutingPolicy(c *BgpConfigSet) *RoutingPolicy { return &RoutingPolicy{ DefinedSets: c.DefinedSets, diff --git a/pkg/config/config.go b/pkg/config/config.go index e6ef0d20..b369760b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,12 +17,6 @@ func ReadConfigFile(configFile, configType string) (*config.BgpConfigSet, error) return config.ReadConfigfile(configFile, configType) } -func ReadConfigFileOnSighup(configFile, configType string) chan *config.BgpConfigSet { - ch := make(chan *config.BgpConfigSet) - go config.ReadConfigfileServe(configFile, configType, ch) - return ch -} - func marshalRouteTargets(l []string) ([]*any.Any, error) { rtList := make([]*any.Any, 0, len(l)) for _, rtString := range l { |