frostfs-node/pkg/util/grace/grace.go
Stanislav Bogatyrev b7b5079934 Add Inner Ring code
2020-07-24 17:07:37 +03:00

27 lines
522 B
Go

package grace
import (
"context"
"os"
"os/signal"
"syscall"
"go.uber.org/zap"
)
// NewGracefulContext returns grace context that cancelled by sigint,
// sigterm and sighup.
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
}