diff options
author | Carl Baldwin <carl@ecbaldwin.net> | 2019-07-24 09:02:26 -0600 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-08-28 09:06:20 +0900 |
commit | 102a5f79d01bfb0da7cb495b03bd732c39f7090b (patch) | |
tree | abd30c124afcabbfc89c94e16ead0522785121ac /cmd/gobgpd/main.go | |
parent | 5d7bf46000f8cae950e9e0c4d9a7a0295e88c7ac (diff) |
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.
Diffstat (limited to 'cmd/gobgpd/main.go')
-rw-r--r-- | cmd/gobgpd/main.go | 36 |
1 files changed, 30 insertions, 6 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) } } |