diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7f32d..47e7eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [3.0.0] - Unreleased +## [3.1.0] - 2022-10-04 +### Fixed +- `main.go` Exit code after showing a version. + +### Changed +- `main.go` Catch both *SIGINT* and *SIGTERM* and exit with **0** code. + +## [3.0.0] - 2022-09-30 ### Changed - **-graphiteAddress** takes `hostname:port` pair. - Multiple senders allowed by repeating **-graphiteAddress** flag. diff --git a/main.go b/main.go index d3420ef..822c301 100644 --- a/main.go +++ b/main.go @@ -4,16 +4,18 @@ import ( "flag" "fmt" "os" + "os/signal" "strconv" "strings" "sync/atomic" + "syscall" "time" log "github.com/sirupsen/logrus" // "github.com/pkg/profile" ) -var version string = "3.0.0" +var version string = "3.1.0" var clog, rlog, tlog, stlog *log.Entry @@ -126,7 +128,7 @@ func main() { if showVersion { fmt.Println(version) - os.Exit(1) + os.Exit(0) } if jsonLog == true { @@ -233,6 +235,7 @@ func main() { go runTransformer(inputChan, outputChans, tenant, forceTenant, prefix, immutablePrefix) go runRouter(statsAddress, statsPort) go updateQueue(1) + go waitForDeath() sleepSeconds := 60 clog.WithFields(log.Fields{"sleepSeconds": sleepSeconds}).Info("Starting a waiting loop.") @@ -268,3 +271,17 @@ func main() { sendStateMetrics(inputChan) } } + +func waitForDeath() { + clog.Info("Starting Wait For Death loop.") + cancelChan := make(chan os.Signal, 1) + signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT) + + for { + time.Sleep(time.Duration(1) * time.Second) + + sig := <-cancelChan + clog.WithFields(log.Fields{"signal": sig}).Info("Caught signal. Terminating.") + os.Exit(0) + } +}