traefik/pkg/server/server_signals.go

38 lines
769 B
Go
Raw Normal View History

// +build !windows
package server
import (
"os/signal"
"syscall"
2019-08-03 01:58:23 +00:00
"github.com/containous/traefik/v2/pkg/log"
)
2017-11-24 18:18:03 +00:00
func (s *Server) configureSignals() {
2018-03-14 12:14:03 +00:00
signal.Notify(s.signals, syscall.SIGUSR1)
}
2018-09-06 12:24:03 +00:00
func (s *Server) listenSignals(stop chan bool) {
for {
2018-09-06 12:24:03 +00:00
select {
case <-stop:
return
case sig := <-s.signals:
2019-02-05 16:10:03 +00:00
if sig == syscall.SIGUSR1 {
2018-11-14 09:18:03 +00:00
log.WithoutContext().Infof("Closing and re-opening log files for rotation: %+v", sig)
2018-09-06 12:24:03 +00:00
if s.accessLoggerMiddleware != nil {
if err := s.accessLoggerMiddleware.Rotate(); err != nil {
2018-11-14 09:18:03 +00:00
log.WithoutContext().Errorf("Error rotating access log: %v", err)
2018-09-06 12:24:03 +00:00
}
}
2018-09-06 12:24:03 +00:00
if err := log.RotateFile(); err != nil {
2018-11-14 09:18:03 +00:00
log.WithoutContext().Errorf("Error rotating traefik log: %v", err)
2018-09-06 12:24:03 +00:00
}
}
}
}
}