Reopen the events log if it's removed or modified while mothd is running

This commit is contained in:
Donaldson 2020-11-17 12:13:30 -06:00
parent caadbced8c
commit 0efcb24d45
4 changed files with 8 additions and 9 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [v3.6.2] - 2020-11-17 ## [v3.6.2] - 2020-11-17
### Fixed ### Fixed
- Re-open events.log if it's modified or removed while the daemon is running
- Removed the "disabled" log, which was getting sent out way too frequently, - Removed the "disabled" log, which was getting sent out way too frequently,
and caused outages due to poor logic handling event queues and caused outages due to poor logic handling event queues

View File

@ -35,7 +35,6 @@ type Instance struct {
jPuzzleList []byte jPuzzleList []byte
jPointsLog []byte jPointsLog []byte
eventStream chan string eventStream chan string
eventLogWriter io.WriteCloser
nextAttempt map[string]time.Time nextAttempt map[string]time.Time
nextAttemptMutex *sync.RWMutex nextAttemptMutex *sync.RWMutex
mux *http.ServeMux mux *http.ServeMux
@ -49,12 +48,6 @@ func (ctx *Instance) Initialize() error {
if _, err := os.Stat(ctx.StateDir); err != nil { if _, err := os.Stat(ctx.StateDir); err != nil {
return err return err
} }
if f, err := os.OpenFile(ctx.StatePath("events.log"), os.O_RDWR|os.O_CREATE, 0644); err != nil {
return err
} else {
// This stays open for the life of the process
ctx.eventLogWriter = f
}
ctx.Base = strings.TrimRight(ctx.Base, "/") ctx.Base = strings.TrimRight(ctx.Base, "/")
ctx.categories = map[string]*Mothball{} ctx.categories = map[string]*Mothball{}

View File

@ -327,7 +327,13 @@ func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) {
case <-ctx.update: case <-ctx.update:
// log.Print("Forced update") // log.Print("Forced update")
case msg := <-ctx.eventStream: case msg := <-ctx.eventStream:
fmt.Fprintln(ctx.eventLogWriter, msg) // log.Print("Writing events log")
func () {
if eventLogWriter, err := os.OpenFile(ctx.StatePath("events.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644); err == nil {
defer eventLogWriter.Close()
fmt.Fprintln(eventLogWriter, msg)
}
}()
case <-time.After(maintenanceInterval): case <-time.After(maintenanceInterval):
// log.Print("Housekeeping...") // log.Print("Housekeeping...")
} }

View File

@ -73,7 +73,6 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer ctx.eventLogWriter.Close()
// Add some MIME extensions // Add some MIME extensions
// Doing this avoids decompressing a mothball entry twice per request // Doing this avoids decompressing a mothball entry twice per request