Skip to content

Commit

Permalink
unregister signal handler after first invocation.
Browse files Browse the repository at this point in the history
 * First Ctrl-C will initiate graceful shutdown
 * Second Ctrl-C will terminate the program

 refs #10
  • Loading branch information
boz committed Sep 28, 2017
1 parent 19ea777 commit 15d7ebc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cmd/kail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,39 @@ func main() {

ctx, cancel := context.WithCancel(ctx)

go watchSignals(ctx, cancel)
sigch := watchSignals(ctx, cancel)

ds := createDS(ctx, cs, dsb)

if *flagDryRun {

listPods(ds)
ds.Close()
cancel()
<-ds.Done()
return

} else {

streamLogs(createController(ctx, cs, ds))

}

controller := createController(ctx, cs, ds)
streamLogs(controller)
cancel()

<-ds.Done()
<-controller.Done()
<-sigch
}

func watchSignals(ctx context.Context, cancel context.CancelFunc) {
func watchSignals(ctx context.Context, cancel context.CancelFunc) <-chan struct{} {
donech := make(chan struct{})
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, syscall.SIGINT, syscall.SIGHUP)
go func() {
defer close(donech)
defer signal.Stop(sigch)
select {
case <-ctx.Done():
case <-sigch:
cancel()
}
}()
return donech
}

func createLog() logutil.Log {
Expand Down

0 comments on commit 15d7ebc

Please sign in to comment.