2017-08-11 10:04:58 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2017-09-26 08:22:03 +00:00
|
|
|
"time"
|
2017-08-11 10:04:58 +00:00
|
|
|
|
|
|
|
"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-08-11 10:04:58 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:18:03 +00:00
|
|
|
func (s *Server) listenSignals() {
|
2017-08-11 10:04:58 +00:00
|
|
|
for {
|
2017-11-24 18:18:03 +00:00
|
|
|
sig := <-s.signals
|
2017-08-11 10:04:58 +00:00
|
|
|
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 {
|
2017-08-11 10:04:58 +00:00
|
|
|
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)
|
2017-08-11 10:04:58 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Infof("I have to go... %+v", sig)
|
2017-11-24 18:18:03 +00:00
|
|
|
reqAcceptGraceTimeOut := time.Duration(s.globalConfiguration.LifeCycle.RequestAcceptGraceTimeout)
|
2017-09-26 08:22:03 +00:00
|
|
|
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()
|
2017-08-11 10:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|