diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-16 06:20:11 -0700 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-16 06:20:11 -0700 |
commit | b65dd149f03d099dc9023db9e2277f8abd90a29b (patch) | |
tree | ae577af53b21ea488544014fc4fd8bd3665b84fa /config | |
parent | b290ec7e7eddf90be0bdb0aa00a387c1a2ebb8aa (diff) |
server: move SIGHUP handling to config file reader goroutine
the main goroutine doesn't need to do so.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r-- | config/serve.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/config/serve.go b/config/serve.go index 8c7d833c..4b5fbbe9 100644 --- a/config/serve.go +++ b/config/serve.go @@ -3,7 +3,10 @@ package config import ( log "github.com/Sirupsen/logrus" "github.com/spf13/viper" + "os" + "os/signal" "reflect" + "syscall" ) type BgpConfigSet struct { @@ -11,11 +14,12 @@ type BgpConfigSet struct { Policy RoutingPolicy } -func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet, reloadCh chan bool) { +func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet) { + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGHUP) + cnt := 0 for { - <-reloadCh - b := Bgp{} v := viper.New() v.SetConfigFile(path) @@ -53,8 +57,11 @@ func ReadConfigfileServe(path, format string, configCh chan BgpConfigSet, reload PolicyDefinitions: c.PolicyDefinitions, }, } + select { + case <-sigCh: + log.Info("reload the config file") + } continue - ERROR: if cnt == 0 { log.Fatal("can't read config file ", path, ", ", err) |