Skip to content

Commit

Permalink
Merge pull request #105 from jharshman/fix-heartbeat-func
Browse files Browse the repository at this point in the history
Fix unexpected exit behavior in heartbeat func
  • Loading branch information
jehiah authored Nov 30, 2020
2 parents 2be1d05 + d2a8327 commit efaec0f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions statsdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,21 +578,20 @@ func tcpListener() {

func heartbeat() {
_, err := os.Stat(*heartbeatFilePath)
if os.IsNotExist(err) {
if err != nil && os.IsNotExist(err) {
file, err := os.Create(*heartbeatFilePath)
if err != nil {
log.Fatalf("ERROR: Creating heartbeat file - %s", err)
}
defer file.Close()
} else {
currentTime := time.Now()
err = os.Chtimes(*heartbeatFilePath, currentTime, currentTime)
if err != nil {
log.Fatalf("ERROR: Touching %s", err)
}
} else if err != nil {
log.Fatalf("ERROR: %s", err)
}

currentTime := time.Now()
err = os.Chtimes(*heartbeatFilePath, currentTime, currentTime)
if err != nil {
log.Fatalf("ERROR: %s", err)
log.Fatalf("ERROR: Touching %s", err)
}
}

Expand Down

0 comments on commit efaec0f

Please sign in to comment.