Improve server shutdown
Less likely to corrupt data now.
This commit is contained in:
parent
0fcc67c121
commit
7847236dbc
14
main.go
14
main.go
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user