HUP on circologd clears the buffer
This commit is contained in:
parent
7704c5ac70
commit
a990422953
2 changed files with 22 additions and 7 deletions
|
@ -31,7 +31,7 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
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)
|
hub := circolog.NewHub(*bufsize)
|
||||||
handler := syslog.NewChannelHandler(hub.LogMessages)
|
handler := syslog.NewChannelHandler(hub.LogMessages)
|
||||||
|
@ -84,10 +84,15 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
// TODO: now we are ready
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case sig := <-interrupt:
|
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)
|
log.Println("Quitting because of signal", sig)
|
||||||
server.Kill()
|
server.Kill()
|
||||||
if err := httpServer.Close(); err != nil {
|
if err := httpServer.Close(); err != nil {
|
||||||
|
@ -96,4 +101,5 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
9
hub.go
9
hub.go
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue