summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-03-16 06:20:11 -0700
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-03-16 06:20:11 -0700
commitb65dd149f03d099dc9023db9e2277f8abd90a29b (patch)
treeae577af53b21ea488544014fc4fd8bd3665b84fa
parentb290ec7e7eddf90be0bdb0aa00a387c1a2ebb8aa (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>
-rw-r--r--config/serve.go15
-rw-r--r--gobgpd/main.go32
2 files changed, 24 insertions, 23 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)
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 15ad1a56..f60f250b 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -37,7 +37,7 @@ import (
func main() {
sigCh := make(chan os.Signal, 1)
- signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGUSR1)
+ signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGUSR1)
var opts struct {
ConfigFile string `short:"f" long:"config-file" description:"specifying a config file"`
@@ -160,10 +160,8 @@ func main() {
}
configCh := make(chan config.BgpConfigSet)
- reloadCh := make(chan bool)
if opts.Dry {
- go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh, reloadCh)
- reloadCh <- true
+ go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh)
c := <-configCh
if opts.LogLevel == "debug" {
p.Println(c)
@@ -172,8 +170,17 @@ func main() {
}
log.Info("gobgpd started")
-
bgpServer := server.NewBgpServer()
+ go bgpServer.Serve()
+
+ // start grpc Server
+ grpcServer := server.NewGrpcServer(opts.GrpcPort, bgpServer.GrpcReqCh)
+ go func() {
+ if err := grpcServer.Serve(); err != nil {
+ log.Fatalf("failed to listen grpc port: %s", err)
+ }
+ }()
+
if opts.Ops {
m, err := ops.NewOpsManager(bgpServer.GrpcReqCh)
if err != nil {
@@ -183,18 +190,8 @@ func main() {
log.Info("Coordination with OpenSwitch")
m.Serve()
} else if opts.ConfigFile != "" {
- go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh, reloadCh)
- reloadCh <- true
+ go config.ReadConfigfileServe(opts.ConfigFile, opts.ConfigType, configCh)
}
- go bgpServer.Serve()
-
- // start grpc Server
- grpcServer := server.NewGrpcServer(opts.GrpcPort, bgpServer.GrpcReqCh)
- go func() {
- if err := grpcServer.Serve(); err != nil {
- log.Fatalf("failed to listen grpc port: %s", err)
- }
- }()
var bgpConfig *config.Bgp = nil
var policyConfig *config.RoutingPolicy = nil
@@ -256,9 +253,6 @@ func main() {
}
case sig := <-sigCh:
switch sig {
- case syscall.SIGHUP:
- log.Info("reload the config file")
- reloadCh <- true
case syscall.SIGKILL, syscall.SIGTERM:
bgpServer.Shutdown()
case syscall.SIGUSR1: