From f54e2d70dccc68ff2a1e00d4a623da7758d69916 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 22 Apr 2021 11:33:51 +0700 Subject: [PATCH] removed signalctx, added NotifyContext Signed-off-by: Mikhail --- Dockerfile | 2 +- main.go | 14 +++++++++++--- pkg/imports/imports.go | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b4df3b..73a5215 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.15-buster as go +FROM golang:1.16-buster as go ENV GO111MODULE=on ENV CGO_ENABLED=0 ENV GOBIN=/bin diff --git a/main.go b/main.go index 10e5dcd..3e3f172 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,8 @@ import ( "context" "net/url" "os" + "os/signal" + "syscall" "time" "github.com/networkservicemesh/sdk/pkg/tools/opentracing" @@ -40,7 +42,6 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/grpcutils" "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" - "github.com/networkservicemesh/sdk/pkg/tools/signalctx" ) // Config is configuration for cmd-nsmgr-proxy @@ -52,8 +53,15 @@ type Config struct { func main() { // Setup context to catch signals - ctx := signalctx.WithSignals(context.Background()) - ctx, cancel := context.WithCancel(ctx) + ctx, cancel := signal.NotifyContext( + context.Background(), + os.Interrupt, + // More Linux signals here + syscall.SIGHUP, + syscall.SIGTERM, + syscall.SIGQUIT, + ) + defer cancel() // Setup logging logrus.SetFormatter(&nested.Formatter{}) diff --git a/pkg/imports/imports.go b/pkg/imports/imports.go index 1376e89..78c464f 100644 --- a/pkg/imports/imports.go +++ b/pkg/imports/imports.go @@ -30,7 +30,9 @@ import ( _ "google.golang.org/grpc/health/grpc_health_v1" _ "net/url" _ "os" + _ "os/signal" _ "path/filepath" + _ "syscall" _ "testing" _ "time" )