traefik/server/server_signals.go

45 lines
1 KiB
Go
Raw Normal View History

// +build !windows
package server
import (
"os/signal"
"syscall"
"time"
"github.com/containous/traefik/log"
)
2017-11-24 18:18:03 +00:00
func (s *Server) configureSignals() {
signal.Notify(s.signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
}
2017-11-24 18:18:03 +00:00
func (s *Server) listenSignals() {
for {
2017-11-24 18:18:03 +00:00
sig := <-s.signals
switch sig {
case syscall.SIGUSR1:
log.Infof("Closing and re-opening log files for rotation: %+v", sig)
2017-11-24 18:18:03 +00:00
if s.accessLoggerMiddleware != nil {
if err := s.accessLoggerMiddleware.Rotate(); err != nil {
log.Errorf("Error rotating access log: %s", err)
}
}
if err := log.RotateFile(); err != nil {
2017-09-15 13:02:03 +00:00
log.Errorf("Error rotating traefik log: %s", err)
}
default:
log.Infof("I have to go... %+v", sig)
2017-11-24 18:18:03 +00:00
reqAcceptGraceTimeOut := time.Duration(s.globalConfiguration.LifeCycle.RequestAcceptGraceTimeout)
if reqAcceptGraceTimeOut > 0 {
log.Infof("Waiting %s for incoming requests to cease", reqAcceptGraceTimeOut)
time.Sleep(reqAcceptGraceTimeOut)
}
log.Info("Stopping server gracefully")
2017-11-24 18:18:03 +00:00
s.Stop()
}
}
}