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,16 +84,22 @@ func main() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
// TODO: now we are ready
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case sig := <-interrupt:
|
case sig := <-interrupt:
|
||||||
log.Println("Quitting because of signal", sig)
|
if sig == syscall.SIGHUP {
|
||||||
server.Kill()
|
log.Println("Clearing queue")
|
||||||
if err := httpServer.Close(); err != nil {
|
hub.Clear()
|
||||||
fmt.Fprintln(os.Stderr, "Error closing http server:", err)
|
}
|
||||||
|
if sig == syscall.SIGTERM || sig == syscall.SIGINT {
|
||||||
|
log.Println("Quitting because of signal", sig)
|
||||||
|
server.Kill()
|
||||||
|
if err := httpServer.Close(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "Error closing http server:", err)
|
||||||
|
}
|
||||||
|
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