-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #91. Fix checkrr not recovering cleanly from any SIGKILL or SIG…
…SEGV calls
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ Copyright © 2022 aetaric <[email protected]> | |
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
@@ -12,6 +13,7 @@ import ( | |
"syscall" | ||
|
||
"github.com/aetaric/checkrr/check" | ||
"github.com/aetaric/checkrr/features" | ||
"github.com/aetaric/checkrr/webserver" | ||
"github.com/common-nighthawk/go-figure" | ||
"github.com/robfig/cron/v3" | ||
|
@@ -129,13 +131,42 @@ func main() { | |
return nil | ||
}) | ||
|
||
testRunning := false | ||
statsCleanup := features.Stats{} | ||
|
||
DB.Update(func(tx *bolt.Tx) error { | ||
_, err := tx.CreateBucketIfNotExists([]byte("Checkrr-stats")) | ||
if err != nil { | ||
return fmt.Errorf("create bucket: %s", err) | ||
} | ||
|
||
b := tx.Bucket([]byte("Checkrr-stats")) | ||
statdata := b.Get([]byte("current-stats")) | ||
json.Unmarshal(statdata, &statsCleanup) | ||
|
||
if statsCleanup.Running { | ||
log.WithFields(log.Fields{"startup": true}).Warn("Cleaing up previous crash or improper termination of checkrr.") | ||
statsCleanup.Running = false | ||
testRunning = true | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if testRunning { | ||
err := DB.Update(func(tx *bolt.Tx) error { | ||
b := tx.Bucket([]byte("Checkrr-stats")) | ||
json, er := json.Marshal(statsCleanup) | ||
if er != nil { | ||
return er | ||
} | ||
err := b.Put([]byte("current-stats"), json) | ||
return err | ||
}) | ||
if err != nil { | ||
log.WithFields(log.Fields{"Module": "Stats", "DB Update": "Failure"}).Warnf("Error: %v", err.Error()) | ||
} | ||
} | ||
} else { | ||
log.WithFields(log.Fields{"startup": true}).Fatal("Database file path missing or unset, please check your config file.") | ||
} | ||
|