Skip to content

Commit

Permalink
confd: exit handle signals and exit cleanly
Browse files Browse the repository at this point in the history
Confd now captures the SIGINT and SIGTERM singals and exits cleanly.
  • Loading branch information
kelseyhightower committed Jul 6, 2014
1 parent 40b9e8a commit 4eea42f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion confd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/kelseyhightower/confd/backends"
Expand Down Expand Up @@ -61,6 +63,8 @@ func main() {
log.Fatal(err.Error())
}

signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
for {
runErrors := template.ProcessTemplateResources(store)
// If the -onetime flag is passed on the command line we immediately exit
Expand All @@ -71,7 +75,13 @@ func main() {
}
os.Exit(0)
}
time.Sleep(time.Duration(config.Interval()) * time.Second)
select {
case c := <-signalChan:
log.Info(fmt.Sprintf("captured %v exiting...", c))
os.Exit(0)
case <-time.After(time.Duration(config.Interval()) * time.Second):
// Continue processing templates.
}
}
}

Expand Down

0 comments on commit 4eea42f

Please sign in to comment.