Add graceful shutdown on SIGTERM

This commit is contained in:
Dmitrii Zganiaiko 2023-02-23 12:01:51 +02:00
parent dbd565d361
commit aa1060a60f
No known key found for this signature in database
GPG Key ID: CA539C9166D772D2
1 changed files with 3 additions and 1 deletions

View File

@ -413,6 +413,7 @@ Developer Options:
} }
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
shutdown := make (chan bool, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() { go func() {
@ -433,7 +434,7 @@ Developer Options:
case s == syscall.SIGQUIT: case s == syscall.SIGQUIT:
os.Exit(3) os.Exit(3)
case s == syscall.SIGTERM: case s == syscall.SIGTERM:
os.Exit(0xf) shutdown <- true
} }
} }
}() }()
@ -481,6 +482,7 @@ Developer Options:
AppendOnly: appendOnly, AppendOnly: appendOnly,
AppendFileName: appendFileName, AppendFileName: appendFileName,
QueueFileName: queueFileName, QueueFileName: queueFileName,
Shutdown: shutdown,
} }
if err := server.Serve(opts); err != nil { if err := server.Serve(opts); err != nil {
log.Fatal(err) log.Fatal(err)