From 9965b426af7d4af538432d7b45e5a69dd94d64f5 Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 28 Oct 2024 17:49:50 +0800 Subject: [PATCH] fix: add sigterm signal Signed-off-by: rfyiamcool --- cmd/agent/cmd/root.go | 10 ++++++---- cmd/controller/cmd/root.go | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/agent/cmd/root.go b/cmd/agent/cmd/root.go index 02e66efd6..0b1c9ff38 100644 --- a/cmd/agent/cmd/root.go +++ b/cmd/agent/cmd/root.go @@ -6,12 +6,14 @@ package cmd import ( "context" "fmt" - "github.com/spf13/cobra" - "github.com/spidernet-io/egressgateway/pkg/agent" - "github.com/spidernet-io/egressgateway/pkg/config" "os" "os/signal" "path/filepath" + "syscall" + + "github.com/spf13/cobra" + "github.com/spidernet-io/egressgateway/pkg/agent" + "github.com/spidernet-io/egressgateway/pkg/config" ) var binName = filepath.Base(os.Args[0]) @@ -21,7 +23,7 @@ var rootCmd = &cobra.Command{ Use: binName, Short: "run egress gateway agent", Run: func(cmd *cobra.Command, args []string) { - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() cfg, err := config.LoadConfig(true) diff --git a/cmd/controller/cmd/root.go b/cmd/controller/cmd/root.go index c98fe94cb..6f5f86e80 100644 --- a/cmd/controller/cmd/root.go +++ b/cmd/controller/cmd/root.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" "path/filepath" + "syscall" "github.com/spf13/cobra" @@ -23,7 +24,7 @@ var rootCmd = &cobra.Command{ Use: binName, Short: "run egress gateway controller", Run: func(cmd *cobra.Command, args []string) { - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() cfg, err := config.LoadConfig(false)