From 0efcb24d45727f0a9985e18802c0325e464d377e Mon Sep 17 00:00:00 2001 From: Donaldson Date: Tue, 17 Nov 2020 12:13:30 -0600 Subject: [PATCH] Reopen the events log if it's removed or modified while mothd is running --- CHANGELOG.md | 1 + src/instance.go | 7 ------- src/maintenance.go | 8 +++++++- src/mothd.go | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3d1f0..fe2044a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [v3.6.2] - 2020-11-17 ### 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, and caused outages due to poor logic handling event queues diff --git a/src/instance.go b/src/instance.go index 8565d06..19593e8 100644 --- a/src/instance.go +++ b/src/instance.go @@ -35,7 +35,6 @@ type Instance struct { jPuzzleList []byte jPointsLog []byte eventStream chan string - eventLogWriter io.WriteCloser nextAttempt map[string]time.Time nextAttemptMutex *sync.RWMutex mux *http.ServeMux @@ -49,12 +48,6 @@ func (ctx *Instance) Initialize() error { if _, err := os.Stat(ctx.StateDir); err != nil { 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.categories = map[string]*Mothball{} diff --git a/src/maintenance.go b/src/maintenance.go index 399c103..44079ed 100644 --- a/src/maintenance.go +++ b/src/maintenance.go @@ -327,7 +327,13 @@ func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) { case <-ctx.update: // log.Print("Forced update") 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): // log.Print("Housekeeping...") } diff --git a/src/mothd.go b/src/mothd.go index 36d033b..a61666e 100644 --- a/src/mothd.go +++ b/src/mothd.go @@ -73,7 +73,6 @@ func main() { if err != nil { log.Fatal(err) } - defer ctx.eventLogWriter.Close() // Add some MIME extensions // Doing this avoids decompressing a mothball entry twice per request