Improve server shutdown

Less likely to corrupt data now.
This commit is contained in:
Přemysl Eric Janouch 2019-04-19 12:30:32 +02:00
parent 0fcc67c121
commit 7847236dbc
Signed by: p
GPG Key ID: A0420B94F92B9493

14
main.go
View File

@ -66,16 +66,16 @@ func main() {
}) })
server := &http.Server{Addr: listenAddr} server := &http.Server{Addr: listenAddr}
go func() { errs := make(chan error, 1)
if err := http.ListenAndServe(listenAddr, nil); err != nil && go func() { errs <- server.ListenAndServe() }()
err != http.ErrServerClosed {
log.Fatalln(err)
}
}()
sig := make(chan os.Signal) sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig select {
case <-sig:
case err := <-errs:
log.Println(err)
}
// For simplicity, we'll wait for everything to finish, including snapshots. // For simplicity, we'll wait for everything to finish, including snapshots.
if err := server.Shutdown(context.Background()); err != nil { if err := server.Shutdown(context.Background()); err != nil {