From 102a5f79d01bfb0da7cb495b03bd732c39f7090b Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Wed, 24 Jul 2019 09:02:26 -0600 Subject: Move ReadConfigFileOnSighup to gobgpd main Reloading the config file on SIGHUP is behavior specific to gobgpd. Attempts to expose it through the config API was awkward and could make the api more confusing to use. This change moves that functionality up into the gobgpd main and out of the library. --- cmd/gobgpd/main.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'cmd') 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) } } -- cgit v1.2.3