HUP on circologd clears the buffer

This commit is contained in:
boyska 2018-11-10 18:00:35 +01:00
parent 7704c5ac70
commit a990422953
2 changed files with 22 additions and 7 deletions

View file

@ -31,7 +31,7 @@ func main() {
flag.Parse()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM)
hub := circolog.NewHub(*bufsize)
handler := syslog.NewChannelHandler(hub.LogMessages)
@ -84,10 +84,15 @@ func main() {
}
}()
}
// TODO: now we are ready
for {
select {
case sig := <-interrupt:
if sig == syscall.SIGHUP {
log.Println("Clearing queue")
hub.Clear()
}
if sig == syscall.SIGTERM || sig == syscall.SIGINT {
log.Println("Quitting because of signal", sig)
server.Kill()
if err := httpServer.Close(); err != nil {
@ -97,3 +102,4 @@ func main() {
}
}
}
}

9
hub.go
View file

@ -101,3 +101,12 @@ func (h *Hub) Run() {
}
}
}
// Clear removes every all elements from the buffer
func (h *Hub) Clear() {
buf := h.circbuf
for i := 0; i < buf.Len(); i++ {
buf.Value = nil
buf = buf.Next()
}
}