mirror of
https://github.com/gomods/athens
synced 2026-02-03 08:40:31 +00:00
Handle SIGTERM on unix-like OS (#1805)
This commit is contained in:
+4
-2
@@ -13,6 +13,7 @@ import (
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/gomods/athens/cmd/proxy/actions"
|
||||
"github.com/gomods/athens/internal/shutdown"
|
||||
"github.com/gomods/athens/pkg/build"
|
||||
"github.com/gomods/athens/pkg/config"
|
||||
)
|
||||
@@ -51,8 +52,9 @@ func main() {
|
||||
|
||||
go func() {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, os.Interrupt)
|
||||
<-sigint
|
||||
signal.Notify(sigint, shutdown.GetSignals()...)
|
||||
s := <-sigint
|
||||
log.Printf("Recived signal (%s): Shutting down server", s)
|
||||
|
||||
// We received an interrupt signal, shut down.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(conf.ShutdownTimeout))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//go:build unix
|
||||
|
||||
package shutdown
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// GetSignals returns the appropriate signals to catch for a clean shutdown, dependent on the OS.
|
||||
//
|
||||
// On Unix-like operating systems, it is important to catch SIGTERM in addition to SIGINT.
|
||||
func GetSignals() []os.Signal {
|
||||
return []os.Signal{os.Interrupt, syscall.SIGTERM}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//go:build !unix
|
||||
|
||||
package shutdown
|
||||
|
||||
import "os"
|
||||
|
||||
// GetSignals returns the appropriate signals to catch for a clean shutdown, dependent on the OS.
|
||||
func GetSignals() []os.Signal {
|
||||
return []os.Signal{os.Interrupt}
|
||||
}
|
||||
Reference in New Issue
Block a user