2017-08-11 10:04:58 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2020-02-03 16:56:04 +00:00
|
|
|
"context"
|
2017-08-11 10:04:58 +00:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/log"
|
2017-08-11 10:04:58 +00:00
|
|
|
)
|
|
|
|
|
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)
|
2017-08-11 10:04:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 16:56:04 +00:00
|
|
|
func (s *Server) listenSignals(ctx context.Context) {
|
2017-08-11 10:04:58 +00:00
|
|
|
for {
|
2018-09-06 12:24:03 +00:00
|
|
|
select {
|
2020-02-03 16:56:04 +00:00
|
|
|
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)
|
2017-08-11 10:04:58 +00:00
|
|
|
|
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
|
|
|
}
|
2017-08-11 10:04:58 +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
|
|
|
}
|
2017-08-11 10:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|