forked from TrueCloudLab/frostfs-node
Initial commit
Initial public review release v0.10.0
This commit is contained in:
commit
dadfd90dcd
276 changed files with 46331 additions and 0 deletions
26
lib/fix/grace.go
Normal file
26
lib/fix/grace.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// NewGracefulContext returns graceful context.
|
||||
func NewGracefulContext(l *zap.Logger) context.Context {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
go func() {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
||||
sig := <-ch
|
||||
l.Info("received signal",
|
||||
zap.String("signal", sig.String()))
|
||||
cancel()
|
||||
}()
|
||||
|
||||
return ctx
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue