From 7642a1a9276457920db4208af0d5f00653b93ded Mon Sep 17 00:00:00 2001 From: Dragan Milic Date: Thu, 18 Apr 2024 21:49:33 +0200 Subject: [PATCH] graceful shutdown in SIGINT and SIGTERM --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b04eaeb..9f37bf5 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,8 @@ import ( "fmt" "os" "os/exec" + "os/signal" + "syscall" "time" "github.com/draganm/gorefresh/build" @@ -39,7 +41,8 @@ func main() { return fmt.Errorf("module directory is not a directory") } - ctx := context.Background() + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() eg, ctx := errgroup.WithContext(ctx) @@ -188,6 +191,7 @@ func main() { for { binary, err := readLast(ctx, binaryChan) if err != nil { + procCancel() return fmt.Errorf("failed to get next binary: %w", err) }