Skip to content

Commit

Permalink
Refactor using kubectl as a reference
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Dec 27, 2024
1 parent 274ac0a commit 4974184
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,14 @@ func runExec(ctx context.Context, smpPath string, client *ecs.Client, region str
return err
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

// TODO: handle errors
// Reference: https://github.com/kubernetes/kubectl/blob/master/pkg/util/interrupt/interrupt.go
go func() {
for {
sig := <-sigs
switch sig {
case syscall.SIGINT:
err = syscall.Kill(cmd.Process.Pid, syscall.SIGINT)
if err != nil {
panic(err)
}
case syscall.SIGTERM:
err = syscall.Kill(cmd.Process.Pid, syscall.SIGTERM)
if err != nil {
panic(err)
}
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
sig := <-sigs
err = cmd.Process.Signal(sig)
if err != nil {
panic(err)
}
}()

Expand Down

0 comments on commit 4974184

Please sign in to comment.