Skip to content

Commit

Permalink
v3.1.0:
Browse files Browse the repository at this point in the history
- fix exit code at '-version'
- catch sigint & sigterm and exit with zero
  • Loading branch information
nixargh committed Oct 4, 2022
1 parent b1ad39a commit 2b53adf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -126,7 +128,7 @@ func main() {

if showVersion {
fmt.Println(version)
os.Exit(1)
os.Exit(0)
}

if jsonLog == true {
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 2b53adf

Please sign in to comment.