From c8c7a37c5c0ac937cf4df97e7ba3e276af8e5817 Mon Sep 17 00:00:00 2001 From: Hugo Wetterberg Date: Wed, 23 Jan 2019 19:08:51 +0100 Subject: [PATCH] capture SIGINT and SIGTERM --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 86eaaf3..73c9aeb 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,11 @@ import ( "fmt" "io/ioutil" "log" + "os" + "os/signal" "strconv" "strings" + "syscall" "time" "github.com/aws/aws-sdk-go-v2/aws/awserr" @@ -536,6 +539,19 @@ func GetAugmentedTasks(svc *ecs.ECS, svcec2 *ec2.EC2, clusterArns []*string) ([] func main() { flag.Parse() + sig := make(chan os.Signal, 1) + signal.Notify(sig, + syscall.SIGTERM, + syscall.SIGINT) + + go func() { + s := <-sig + if ss, ok := s.(syscall.Signal); ok { + os.Exit(int(ss) + 128) + } + os.Exit(128) + }() + config, err := external.LoadDefaultAWSConfig() if err != nil { logError(err)