diff --git a/btcd.go b/btcd.go index 4aad4b51..c0a186f9 100644 --- a/btcd.go +++ b/btcd.go @@ -94,6 +94,11 @@ func btcdMain(serverChan chan<- *server) error { cfg.Listeners, err) return err } + addInterruptHandler(func() { + btcdLog.Infof("Gracefully shutting down the server...") + server.Stop() + server.WaitForShutdown() + }) server.Start() if serverChan != nil { serverChan <- server @@ -107,6 +112,7 @@ func btcdMain(serverChan chan<- *server) error { // for the interrupt handler goroutine to finish. go func() { server.WaitForShutdown() + srvrLog.Infof("Server shutdown complete") shutdownChannel <- true }() diff --git a/server.go b/server.go index 639a005a..524d8601 100644 --- a/server.go +++ b/server.go @@ -728,7 +728,6 @@ func (s *server) Stop() error { // WaitForShutdown blocks until the main listener and peer handlers are stopped. func (s *server) WaitForShutdown() { s.wg.Wait() - srvrLog.Infof("Server shutdown complete") } // ScheduleShutdown schedules a server shutdown after the specified duration.