diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-06 23:28:42 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-06 23:28:42 +0900 |
commit | b01b65b2d3da124ea55d21e6e31f5fcf72cd80fb (patch) | |
tree | b3693d07cab23780b42c9e1ac285e2fec5682f14 | |
parent | 74774b39d28541684eb9a547fab794210d932ef7 (diff) |
server: fix TERM signal handling
gobgpd should die after sending a notification all the peers in
the established state.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/server.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index 82193d00..ff4b292f 100644 --- a/server/server.go +++ b/server/server.go @@ -106,6 +106,7 @@ type BgpServer struct { roaClient *roaClient bmpClient *bmpClient bmpConnCh chan *bmpConn + shutdown bool } func NewBgpServer(port int) *BgpServer { @@ -785,6 +786,18 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * msgs = append(msgs, newSenderMsg(peer, table.CreateUpdateMsgFromPaths(pathList))) } } else { + if server.shutdown && nextState == bgp.BGP_FSM_IDLE { + die := true + for _, p := range server.neighborMap { + if p.fsm.state != bgp.BGP_FSM_IDLE { + die = false + break + } + } + if die { + os.Exit(0) + } + } peer.conf.Timers.TimersState.Downtime = time.Now().Unix() } // clear counter @@ -876,6 +889,7 @@ func (server *BgpServer) PeerUpdate(peer config.Neighbor) { } func (server *BgpServer) Shutdown() { + server.shutdown = true for _, p := range server.neighborMap { p.fsm.adminStateCh <- ADMIN_STATE_DOWN } |