Skip to content

Commit

Permalink
removed signalctx, added NotifyContext (#76)
Browse files Browse the repository at this point in the history
* removed signalctx, added NotifyContext

Signed-off-by: Mikhail <avramenkomihail15@gmail.com>

* refactored main function

Signed-off-by: Mikhail <avramenkomihail15@gmail.com>
  • Loading branch information
Mixaster995 authored Apr 22, 2021
1 parent 6035ffb commit 5f5a5d9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG VPP_VERSION=v20.09
FROM ghcr.io/edwarnicke/govpp/vpp:${VPP_VERSION} as go
COPY --from=golang:1.15.3-buster /usr/local/go/ /go
COPY --from=golang:1.16.3-buster /usr/local/go/ /go
ENV PATH ${PATH}:/go/bin
ENV GO111MODULE=on
ENV CGO_ENABLED=0
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/edwarnicke/debug v1.0.0
github.com/edwarnicke/grpcfd v0.0.0-20210219150442-10fb469a6976
github.com/edwarnicke/signalctx v0.0.0-20201105214533-3a35840b3011
github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d
github.com/google/uuid v1.1.2
github.com/kelseyhightower/envconfig v1.4.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ github.com/edwarnicke/log v1.0.0/go.mod h1:eWsQQlQ0IU5wHlJvyXFH3dS8s2g9GzN7JnXod
github.com/edwarnicke/serialize v0.0.0-20200705214914-ebc43080eecf/go.mod h1:XvbCO/QGsl3X8RzjBMoRpkm54FIAZH5ChK2j+aox7pw=
github.com/edwarnicke/serialize v1.0.7 h1:geX8vmyu8Ij2S5fFIXjy9gBDkKxXnrMIzMoDvV0Ddac=
github.com/edwarnicke/serialize v1.0.7/go.mod h1:y79KgU2P7ALH/4j37uTSIdNavHFNttqN7pzO6Y8B2aw=
github.com/edwarnicke/signalctx v0.0.0-20201105214533-3a35840b3011 h1:rlA4xj11pzxP9w/qVP11qZkRN+7UfA8MiW6pPljW0CM=
github.com/edwarnicke/signalctx v0.0.0-20201105214533-3a35840b3011/go.mod h1:Z9/3G9n/oPyXJzsF4ucVh8YOxTlTidDLqOeWlGV1JAw=
github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d h1:Okg1uazbTBFvNTrWP5AbTLgG/xMsnZNIobxJYpyvyK8=
github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d/go.mod h1:2KXgJqOUUCh9S4Zs2jAycQLqAcRGge3q+GXV2rN55ZQ=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
3 changes: 2 additions & 1 deletion internal/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
_ "github.com/antonfisher/nested-logrus-formatter"
_ "github.com/edwarnicke/debug"
_ "github.com/edwarnicke/grpcfd"
_ "github.com/edwarnicke/signalctx"
_ "github.com/edwarnicke/vpphelper"
_ "github.com/google/uuid"
_ "github.com/kelseyhightower/envconfig"
Expand All @@ -33,5 +32,7 @@ import (
_ "google.golang.org/grpc/credentials"
_ "net/url"
_ "os"
_ "os/signal"
_ "syscall"
_ "time"
)
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"fmt"
"net/url"
"os"
"os/signal"
"syscall"
"time"

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/edwarnicke/debug"
"github.com/edwarnicke/grpcfd"
"github.com/edwarnicke/signalctx"
"github.com/edwarnicke/vpphelper"
"github.com/google/uuid"
"github.com/kelseyhightower/envconfig"
Expand Down Expand Up @@ -69,8 +70,8 @@ func main() {
// ********************************************************************************
// setup context to catch signals
// ********************************************************************************
ctx := signalctx.WithSignals(context.Background())
ctx, cancel := context.WithCancel(ctx)
ctx, cancel := notifyContext()
defer cancel()
// ********************************************************************************
// setup logging
// ********************************************************************************
Expand Down Expand Up @@ -230,3 +231,14 @@ func exitOnErrCh(ctx context.Context, cancel context.CancelFunc, errCh <-chan er
cancel()
}(ctx, errCh)
}

func notifyContext() (context.Context, context.CancelFunc) {
return signal.NotifyContext(
context.Background(),
os.Interrupt,
// More Linux signals here
syscall.SIGHUP,
syscall.SIGTERM,
syscall.SIGQUIT,
)
}

0 comments on commit 5f5a5d9

Please sign in to comment.