traefik/pkg/server/server_signals.go

36 lines
649 B
Go
Raw Normal View History

2021-09-16 07:16:07 +00:00
//go:build !windows
// +build !windows
package server
import (
"context"
"os/signal"
"syscall"
2022-11-21 17:36:05 +00:00
"github.com/rs/zerolog/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 {
2022-11-21 17:36:05 +00:00
log.Info().Msgf("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 {
2022-11-21 17:36:05 +00:00
log.Error().Err(err).Msg("Error rotating access log")
2018-09-06 12:24:03 +00:00
}
}
}
}
}
}