mirror of https://github.com/dirtbags/moth.git
Reopen the events log if it's removed or modified while mothd is running
This commit is contained in:
parent
caadbced8c
commit
0efcb24d45
|
@ -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
|
||||
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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...")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue