Shutdown server fully on ctrl-c

since we don't wait for peers, this largely just waits for the server procs
themselves to die. Unless the entire server is wedged (which is what kill -9 is
for) this should always shut down fairly swiftly.

This should mean we sync addrmanager and disestablish upnp correctly on
interrupt.

Discussed with davec.
This commit is contained in:
Owain G. Ainsworth 2013-12-10 18:21:34 +00:00
parent f8e88df237
commit 2a554c43b0
2 changed files with 6 additions and 1 deletions

View file

@ -94,6 +94,11 @@ func btcdMain(serverChan chan<- *server) error {
cfg.Listeners, err) cfg.Listeners, err)
return err return err
} }
addInterruptHandler(func() {
btcdLog.Infof("Gracefully shutting down the server...")
server.Stop()
server.WaitForShutdown()
})
server.Start() server.Start()
if serverChan != nil { if serverChan != nil {
serverChan <- server serverChan <- server
@ -107,6 +112,7 @@ func btcdMain(serverChan chan<- *server) error {
// for the interrupt handler goroutine to finish. // for the interrupt handler goroutine to finish.
go func() { go func() {
server.WaitForShutdown() server.WaitForShutdown()
srvrLog.Infof("Server shutdown complete")
shutdownChannel <- true shutdownChannel <- true
}() }()

View file

@ -728,7 +728,6 @@ func (s *server) Stop() error {
// WaitForShutdown blocks until the main listener and peer handlers are stopped. // WaitForShutdown blocks until the main listener and peer handlers are stopped.
func (s *server) WaitForShutdown() { func (s *server) WaitForShutdown() {
s.wg.Wait() s.wg.Wait()
srvrLog.Infof("Server shutdown complete")
} }
// ScheduleShutdown schedules a server shutdown after the specified duration. // ScheduleShutdown schedules a server shutdown after the specified duration.