Create buffered signals channel
This commit is contained in:
parent
5ca210fa60
commit
95e0633b2f
2 changed files with 3 additions and 21 deletions
|
@ -1,20 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ContextWithSignal creates a context canceled when SIGINT or SIGTERM are notified.
|
|
||||||
func ContextWithSignal(ctx context.Context) context.Context {
|
|
||||||
newCtx, cancel := context.WithCancel(ctx)
|
|
||||||
signals := make(chan os.Signal)
|
|
||||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
go func() {
|
|
||||||
<-signals
|
|
||||||
cancel()
|
|
||||||
}()
|
|
||||||
return newCtx
|
|
||||||
}
|
|
|
@ -6,9 +6,11 @@ import (
|
||||||
stdlog "log"
|
stdlog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/go-systemd/daemon"
|
"github.com/coreos/go-systemd/daemon"
|
||||||
|
@ -119,7 +121,7 @@ func runCmd(staticConfiguration *static.Configuration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := cmd.ContextWithSignal(context.Background())
|
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
if staticConfiguration.Experimental != nil && staticConfiguration.Experimental.DevPlugin != nil {
|
if staticConfiguration.Experimental != nil && staticConfiguration.Experimental.DevPlugin != nil {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
|
|
Loading…
Reference in a new issue