traefik/pkg/server/server_signals.go

39 lines
788 B
Go
Raw Normal View History

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