Skip to content

Commit

Permalink
cmd: Support double signal handling
Browse files Browse the repository at this point in the history
Signed-off-by: Kosy Anyanwu <kosy@kinvolk.io>
  • Loading branch information
kosyfrances committed May 25, 2018
1 parent 3ff6dd4 commit 46ed0b2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/habitat-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,17 @@ func run() int {
// Relay these signals to the `term` channel.
signal.Notify(term, syscall.SIGINT, syscall.SIGTERM)

select {
case <-term:
go func() {
<-term
level.Info(logger).Log("msg", "received SIGTERM, exiting gracefully...")
case <-ctx.Done():
level.Info(logger).Log("msg", "context channel closed, exiting")
}
cancelFunc()

<-term
os.Exit(1)
}()

<-ctx.Done()
level.Info(logger).Log("msg", "context channel closed, exiting")

return 0
}
Expand Down

0 comments on commit 46ed0b2

Please sign in to comment.