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:
parent
f8e88df237
commit
2a554c43b0
2 changed files with 6 additions and 1 deletions
6
btcd.go
6
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
|
||||
}()
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue