mirror of
https://github.com/rancher/types.git
synced 2025-09-01 05:09:10 +00:00
Update vendor
This commit is contained in:
28
vendor/github.com/rancher/norman/signal/sigterm.go
generated
vendored
Normal file
28
vendor/github.com/rancher/norman/signal/sigterm.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
package signal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func SigTermCancelContext(ctx context.Context) context.Context {
|
||||
term := make(chan os.Signal)
|
||||
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-term:
|
||||
logrus.Infof("Received SIGTERM, cancelling")
|
||||
cancel()
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}()
|
||||
|
||||
return ctx
|
||||
}
|
Reference in New Issue
Block a user