traefik/pkg/server/server_signals.go

39 lines
791 B
Go
Raw Normal View History

// +build !windows
package server
import (
"context"
"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)
}
func (s *Server) listenSignals(ctx context.Context) {
for {
2018-09-06 12:24:03 +00:00
select {
case <-ctx.Done():
2018-09-06 12:24:03 +00:00
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
}
}
}
}
}