Change server receiver name.
This commit is contained in:
parent
f6181ef3e2
commit
011b748a55
4 changed files with 208 additions and 208 deletions
|
@ -60,7 +60,7 @@ type Provider struct {
|
||||||
DCOSToken string `description:"DCOSToken for DCOS environment, This will override the Authorization header" export:"true"`
|
DCOSToken string `description:"DCOSToken for DCOS environment, This will override the Authorization header" export:"true"`
|
||||||
MarathonLBCompatibility bool `description:"Add compatibility with marathon-lb labels" export:"true"`
|
MarathonLBCompatibility bool `description:"Add compatibility with marathon-lb labels" export:"true"`
|
||||||
FilterMarathonConstraints bool `description:"Enable use of Marathon constraints in constraint filtering" export:"true"`
|
FilterMarathonConstraints bool `description:"Enable use of Marathon constraints in constraint filtering" export:"true"`
|
||||||
TLS *types.ClientTLS `description:"Enable Docker TLS support" export:"true"`
|
TLS *types.ClientTLS `description:"Enable TLS support" export:"true"`
|
||||||
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon" export:"true"`
|
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon" export:"true"`
|
||||||
KeepAlive flaeg.Duration `description:"Set a non-default TCP Keep Alive time in seconds" export:"true"`
|
KeepAlive flaeg.Duration `description:"Set a non-default TCP Keep Alive time in seconds" export:"true"`
|
||||||
ForceTaskHostname bool `description:"Force to use the task's hostname." export:"true"`
|
ForceTaskHostname bool `description:"Force to use the task's hostname." export:"true"`
|
||||||
|
|
388
server/server.go
388
server/server.go
|
@ -188,34 +188,34 @@ func createRootCACertPool(rootCAs traefikTls.RootCAs) *x509.CertPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the server.
|
// Start starts the server.
|
||||||
func (server *Server) Start() {
|
func (s *Server) Start() {
|
||||||
server.startHTTPServers()
|
s.startHTTPServers()
|
||||||
server.startLeadership()
|
s.startLeadership()
|
||||||
server.routinesPool.Go(func(stop chan bool) {
|
s.routinesPool.Go(func(stop chan bool) {
|
||||||
server.listenProviders(stop)
|
s.listenProviders(stop)
|
||||||
})
|
})
|
||||||
server.routinesPool.Go(func(stop chan bool) {
|
s.routinesPool.Go(func(stop chan bool) {
|
||||||
server.listenConfigurations(stop)
|
s.listenConfigurations(stop)
|
||||||
})
|
})
|
||||||
server.configureProviders()
|
s.configureProviders()
|
||||||
server.startProviders()
|
s.startProviders()
|
||||||
go server.listenSignals()
|
go s.listenSignals()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait blocks until server is shutted down.
|
// Wait blocks until server is shutted down.
|
||||||
func (server *Server) Wait() {
|
func (s *Server) Wait() {
|
||||||
<-server.stopChan
|
<-s.stopChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops the server
|
// Stop stops the server
|
||||||
func (server *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
defer log.Info("Server stopped")
|
defer log.Info("Server stopped")
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for sepn, sep := range server.serverEntryPoints {
|
for sepn, sep := range s.serverEntryPoints {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(serverEntryPointName string, serverEntryPoint *serverEntryPoint) {
|
go func(serverEntryPointName string, serverEntryPoint *serverEntryPoint) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
graceTimeOut := time.Duration(server.globalConfiguration.LifeCycle.GraceTimeOut)
|
graceTimeOut := time.Duration(s.globalConfiguration.LifeCycle.GraceTimeOut)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), graceTimeOut)
|
ctx, cancel := context.WithTimeout(context.Background(), graceTimeOut)
|
||||||
log.Debugf("Waiting %s seconds before killing connections on entrypoint %s...", graceTimeOut, serverEntryPointName)
|
log.Debugf("Waiting %s seconds before killing connections on entrypoint %s...", graceTimeOut, serverEntryPointName)
|
||||||
if err := serverEntryPoint.httpServer.Shutdown(ctx); err != nil {
|
if err := serverEntryPoint.httpServer.Shutdown(ctx); err != nil {
|
||||||
|
@ -227,12 +227,12 @@ func (server *Server) Stop() {
|
||||||
}(sepn, sep)
|
}(sepn, sep)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
server.stopChan <- true
|
s.stopChan <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close destroys the server
|
// Close destroys the server
|
||||||
func (server *Server) Close() {
|
func (s *Server) Close() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(server.globalConfiguration.LifeCycle.GraceTimeOut))
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.globalConfiguration.LifeCycle.GraceTimeOut))
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
if ctx.Err() == context.Canceled {
|
if ctx.Err() == context.Canceled {
|
||||||
|
@ -243,109 +243,109 @@ func (server *Server) Close() {
|
||||||
}
|
}
|
||||||
}(ctx)
|
}(ctx)
|
||||||
stopMetricsClients()
|
stopMetricsClients()
|
||||||
server.stopLeadership()
|
s.stopLeadership()
|
||||||
server.routinesPool.Cleanup()
|
s.routinesPool.Cleanup()
|
||||||
close(server.configurationChan)
|
close(s.configurationChan)
|
||||||
close(server.configurationValidatedChan)
|
close(s.configurationValidatedChan)
|
||||||
signal.Stop(server.signals)
|
signal.Stop(s.signals)
|
||||||
close(server.signals)
|
close(s.signals)
|
||||||
close(server.stopChan)
|
close(s.stopChan)
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
if err := server.accessLoggerMiddleware.Close(); err != nil {
|
if err := s.accessLoggerMiddleware.Close(); err != nil {
|
||||||
log.Errorf("Error closing access log file: %s", err)
|
log.Errorf("Error closing access log file: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) startLeadership() {
|
func (s *Server) startLeadership() {
|
||||||
if server.leadership != nil {
|
if s.leadership != nil {
|
||||||
server.leadership.Participate(server.routinesPool)
|
s.leadership.Participate(s.routinesPool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) stopLeadership() {
|
func (s *Server) stopLeadership() {
|
||||||
if server.leadership != nil {
|
if s.leadership != nil {
|
||||||
server.leadership.Stop()
|
s.leadership.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) startHTTPServers() {
|
func (s *Server) startHTTPServers() {
|
||||||
server.serverEntryPoints = server.buildEntryPoints(server.globalConfiguration)
|
s.serverEntryPoints = s.buildEntryPoints(s.globalConfiguration)
|
||||||
|
|
||||||
for newServerEntryPointName, newServerEntryPoint := range server.serverEntryPoints {
|
for newServerEntryPointName, newServerEntryPoint := range s.serverEntryPoints {
|
||||||
serverEntryPoint := server.setupServerEntryPoint(newServerEntryPointName, newServerEntryPoint)
|
serverEntryPoint := s.setupServerEntryPoint(newServerEntryPointName, newServerEntryPoint)
|
||||||
go server.startServer(serverEntryPoint, server.globalConfiguration)
|
go s.startServer(serverEntryPoint, s.globalConfiguration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) setupServerEntryPoint(newServerEntryPointName string, newServerEntryPoint *serverEntryPoint) *serverEntryPoint {
|
func (s *Server) setupServerEntryPoint(newServerEntryPointName string, newServerEntryPoint *serverEntryPoint) *serverEntryPoint {
|
||||||
serverMiddlewares := []negroni.Handler{middlewares.NegroniRecoverHandler()}
|
serverMiddlewares := []negroni.Handler{middlewares.NegroniRecoverHandler()}
|
||||||
serverInternalMiddlewares := []negroni.Handler{middlewares.NegroniRecoverHandler()}
|
serverInternalMiddlewares := []negroni.Handler{middlewares.NegroniRecoverHandler()}
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
serverMiddlewares = append(serverMiddlewares, server.accessLoggerMiddleware)
|
serverMiddlewares = append(serverMiddlewares, s.accessLoggerMiddleware)
|
||||||
}
|
}
|
||||||
if server.metricsRegistry.IsEnabled() {
|
if s.metricsRegistry.IsEnabled() {
|
||||||
serverMiddlewares = append(serverMiddlewares, middlewares.NewMetricsWrapper(server.metricsRegistry, newServerEntryPointName))
|
serverMiddlewares = append(serverMiddlewares, middlewares.NewMetricsWrapper(s.metricsRegistry, newServerEntryPointName))
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.API != nil {
|
if s.globalConfiguration.API != nil {
|
||||||
server.globalConfiguration.API.Stats = thoas_stats.New()
|
s.globalConfiguration.API.Stats = thoas_stats.New()
|
||||||
serverMiddlewares = append(serverMiddlewares, server.globalConfiguration.API.Stats)
|
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.Stats)
|
||||||
if server.globalConfiguration.API.Statistics != nil {
|
if s.globalConfiguration.API.Statistics != nil {
|
||||||
server.globalConfiguration.API.StatsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.API.Statistics.RecentErrors)
|
s.globalConfiguration.API.StatsRecorder = middlewares.NewStatsRecorder(s.globalConfiguration.API.Statistics.RecentErrors)
|
||||||
serverMiddlewares = append(serverMiddlewares, server.globalConfiguration.API.StatsRecorder)
|
serverMiddlewares = append(serverMiddlewares, s.globalConfiguration.API.StatsRecorder)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.EntryPoints[newServerEntryPointName].Auth != nil {
|
if s.globalConfiguration.EntryPoints[newServerEntryPointName].Auth != nil {
|
||||||
authMiddleware, err := mauth.NewAuthenticator(server.globalConfiguration.EntryPoints[newServerEntryPointName].Auth)
|
authMiddleware, err := mauth.NewAuthenticator(s.globalConfiguration.EntryPoints[newServerEntryPointName].Auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error starting server: ", err)
|
log.Fatal("Error starting server: ", err)
|
||||||
}
|
}
|
||||||
serverMiddlewares = append(serverMiddlewares, authMiddleware)
|
serverMiddlewares = append(serverMiddlewares, authMiddleware)
|
||||||
serverInternalMiddlewares = append(serverInternalMiddlewares, authMiddleware)
|
serverInternalMiddlewares = append(serverInternalMiddlewares, authMiddleware)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.EntryPoints[newServerEntryPointName].Compress {
|
if s.globalConfiguration.EntryPoints[newServerEntryPointName].Compress {
|
||||||
serverMiddlewares = append(serverMiddlewares, &middlewares.Compress{})
|
serverMiddlewares = append(serverMiddlewares, &middlewares.Compress{})
|
||||||
}
|
}
|
||||||
if len(server.globalConfiguration.EntryPoints[newServerEntryPointName].WhitelistSourceRange) > 0 {
|
if len(s.globalConfiguration.EntryPoints[newServerEntryPointName].WhitelistSourceRange) > 0 {
|
||||||
ipWhitelistMiddleware, err := middlewares.NewIPWhitelister(server.globalConfiguration.EntryPoints[newServerEntryPointName].WhitelistSourceRange)
|
ipWhitelistMiddleware, err := middlewares.NewIPWhitelister(s.globalConfiguration.EntryPoints[newServerEntryPointName].WhitelistSourceRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error starting server: ", err)
|
log.Fatal("Error starting server: ", err)
|
||||||
}
|
}
|
||||||
serverMiddlewares = append(serverMiddlewares, ipWhitelistMiddleware)
|
serverMiddlewares = append(serverMiddlewares, ipWhitelistMiddleware)
|
||||||
serverInternalMiddlewares = append(serverInternalMiddlewares, ipWhitelistMiddleware)
|
serverInternalMiddlewares = append(serverInternalMiddlewares, ipWhitelistMiddleware)
|
||||||
}
|
}
|
||||||
newSrv, listener, err := server.prepareServer(newServerEntryPointName, server.globalConfiguration.EntryPoints[newServerEntryPointName], newServerEntryPoint.httpRouter, serverMiddlewares, serverInternalMiddlewares)
|
newSrv, listener, err := s.prepareServer(newServerEntryPointName, s.globalConfiguration.EntryPoints[newServerEntryPointName], newServerEntryPoint.httpRouter, serverMiddlewares, serverInternalMiddlewares)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error preparing server: ", err)
|
log.Fatal("Error preparing server: ", err)
|
||||||
}
|
}
|
||||||
serverEntryPoint := server.serverEntryPoints[newServerEntryPointName]
|
serverEntryPoint := s.serverEntryPoints[newServerEntryPointName]
|
||||||
serverEntryPoint.httpServer = newSrv
|
serverEntryPoint.httpServer = newSrv
|
||||||
serverEntryPoint.listener = listener
|
serverEntryPoint.listener = listener
|
||||||
|
|
||||||
return serverEntryPoint
|
return serverEntryPoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) listenProviders(stop chan bool) {
|
func (s *Server) listenProviders(stop chan bool) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
case configMsg, ok := <-server.configurationChan:
|
case configMsg, ok := <-s.configurationChan:
|
||||||
if !ok || configMsg.Configuration == nil {
|
if !ok || configMsg.Configuration == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
server.preLoadConfiguration(configMsg)
|
s.preLoadConfiguration(configMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) preLoadConfiguration(configMsg types.ConfigMessage) {
|
func (s *Server) preLoadConfiguration(configMsg types.ConfigMessage) {
|
||||||
providerConfigUpdateMap := map[string]chan types.ConfigMessage{}
|
providerConfigUpdateMap := map[string]chan types.ConfigMessage{}
|
||||||
providersThrottleDuration := time.Duration(server.globalConfiguration.ProvidersThrottleDuration)
|
providersThrottleDuration := time.Duration(s.globalConfiguration.ProvidersThrottleDuration)
|
||||||
server.defaultConfigurationValues(configMsg.Configuration)
|
s.defaultConfigurationValues(configMsg.Configuration)
|
||||||
currentConfigurations := server.currentConfigurations.Get().(types.Configurations)
|
currentConfigurations := s.currentConfigurations.Get().(types.Configurations)
|
||||||
jsonConf, _ := json.Marshal(configMsg.Configuration)
|
jsonConf, _ := json.Marshal(configMsg.Configuration)
|
||||||
log.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf))
|
log.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf))
|
||||||
if configMsg.Configuration == nil || configMsg.Configuration.Backends == nil && configMsg.Configuration.Frontends == nil && configMsg.Configuration.TLSConfiguration == nil {
|
if configMsg.Configuration == nil || configMsg.Configuration.Backends == nil && configMsg.Configuration.Frontends == nil && configMsg.Configuration.TLSConfiguration == nil {
|
||||||
|
@ -356,8 +356,8 @@ func (server *Server) preLoadConfiguration(configMsg types.ConfigMessage) {
|
||||||
if _, ok := providerConfigUpdateMap[configMsg.ProviderName]; !ok {
|
if _, ok := providerConfigUpdateMap[configMsg.ProviderName]; !ok {
|
||||||
providerConfigUpdate := make(chan types.ConfigMessage)
|
providerConfigUpdate := make(chan types.ConfigMessage)
|
||||||
providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdate
|
providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdate
|
||||||
server.routinesPool.Go(func(stop chan bool) {
|
s.routinesPool.Go(func(stop chan bool) {
|
||||||
throttleProviderConfigReload(providersThrottleDuration, server.configurationValidatedChan, providerConfigUpdate, stop)
|
throttleProviderConfigReload(providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdate, stop)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
providerConfigUpdateMap[configMsg.ProviderName] <- configMsg
|
providerConfigUpdateMap[configMsg.ProviderName] <- configMsg
|
||||||
|
@ -393,31 +393,31 @@ func throttleProviderConfigReload(throttle time.Duration, publish chan<- types.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) defaultConfigurationValues(configuration *types.Configuration) {
|
func (s *Server) defaultConfigurationValues(configuration *types.Configuration) {
|
||||||
if configuration == nil || configuration.Frontends == nil {
|
if configuration == nil || configuration.Frontends == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
server.configureFrontends(configuration.Frontends)
|
s.configureFrontends(configuration.Frontends)
|
||||||
server.configureBackends(configuration.Backends)
|
s.configureBackends(configuration.Backends)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) listenConfigurations(stop chan bool) {
|
func (s *Server) listenConfigurations(stop chan bool) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
case configMsg, ok := <-server.configurationValidatedChan:
|
case configMsg, ok := <-s.configurationValidatedChan:
|
||||||
if !ok || configMsg.Configuration == nil {
|
if !ok || configMsg.Configuration == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
server.loadConfiguration(configMsg)
|
s.loadConfiguration(configMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadConfiguration manages dynamically frontends, backends and TLS configurations
|
// loadConfiguration manages dynamically frontends, backends and TLS configurations
|
||||||
func (server *Server) loadConfiguration(configMsg types.ConfigMessage) {
|
func (s *Server) loadConfiguration(configMsg types.ConfigMessage) {
|
||||||
currentConfigurations := server.currentConfigurations.Get().(types.Configurations)
|
currentConfigurations := s.currentConfigurations.Get().(types.Configurations)
|
||||||
|
|
||||||
// Copy configurations to new map so we don't change current if LoadConfig fails
|
// Copy configurations to new map so we don't change current if LoadConfig fails
|
||||||
newConfigurations := make(types.Configurations)
|
newConfigurations := make(types.Configurations)
|
||||||
|
@ -426,24 +426,24 @@ func (server *Server) loadConfiguration(configMsg types.ConfigMessage) {
|
||||||
}
|
}
|
||||||
newConfigurations[configMsg.ProviderName] = configMsg.Configuration
|
newConfigurations[configMsg.ProviderName] = configMsg.Configuration
|
||||||
|
|
||||||
newServerEntryPoints, err := server.loadConfig(newConfigurations, server.globalConfiguration)
|
newServerEntryPoints, err := s.loadConfig(newConfigurations, s.globalConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for newServerEntryPointName, newServerEntryPoint := range newServerEntryPoints {
|
for newServerEntryPointName, newServerEntryPoint := range newServerEntryPoints {
|
||||||
server.serverEntryPoints[newServerEntryPointName].httpRouter.UpdateHandler(newServerEntryPoint.httpRouter.GetHandler())
|
s.serverEntryPoints[newServerEntryPointName].httpRouter.UpdateHandler(newServerEntryPoint.httpRouter.GetHandler())
|
||||||
if &newServerEntryPoint.certs != nil {
|
if &newServerEntryPoint.certs != nil {
|
||||||
server.serverEntryPoints[newServerEntryPointName].certs.Set(newServerEntryPoint.certs.Get())
|
s.serverEntryPoints[newServerEntryPointName].certs.Set(newServerEntryPoint.certs.Get())
|
||||||
}
|
}
|
||||||
log.Infof("Server configuration reloaded on %s", server.serverEntryPoints[newServerEntryPointName].httpServer.Addr)
|
log.Infof("Server configuration reloaded on %s", s.serverEntryPoints[newServerEntryPointName].httpServer.Addr)
|
||||||
}
|
}
|
||||||
server.currentConfigurations.Set(newConfigurations)
|
s.currentConfigurations.Set(newConfigurations)
|
||||||
server.postLoadConfiguration()
|
s.postLoadConfiguration()
|
||||||
} else {
|
} else {
|
||||||
log.Error("Error loading new configuration, aborted ", err)
|
log.Error("Error loading new configuration, aborted ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadHTTPSConfiguration add/delete HTTPS certificate managed dynamically
|
// loadHTTPSConfiguration add/delete HTTPS certificate managed dynamically
|
||||||
func (server *Server) loadHTTPSConfiguration(configurations types.Configurations) (map[string]*traefikTls.DomainsCertificates, error) {
|
func (s *Server) loadHTTPSConfiguration(configurations types.Configurations) (map[string]*traefikTls.DomainsCertificates, error) {
|
||||||
newEPCertificates := make(map[string]*traefikTls.DomainsCertificates)
|
newEPCertificates := make(map[string]*traefikTls.DomainsCertificates)
|
||||||
// Get all certificates
|
// Get all certificates
|
||||||
for _, configuration := range configurations {
|
for _, configuration := range configurations {
|
||||||
|
@ -473,15 +473,15 @@ func (s *serverEntryPoint) getCertificate(clientHello *tls.ClientHelloInfo) (*tl
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) postLoadConfiguration() {
|
func (s *Server) postLoadConfiguration() {
|
||||||
if server.globalConfiguration.ACME == nil {
|
if s.globalConfiguration.ACME == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if server.leadership != nil && !server.leadership.IsLeader() {
|
if s.leadership != nil && !s.leadership.IsLeader() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.ACME.OnHostRule {
|
if s.globalConfiguration.ACME.OnHostRule {
|
||||||
currentConfigurations := server.currentConfigurations.Get().(types.Configurations)
|
currentConfigurations := s.currentConfigurations.Get().(types.Configurations)
|
||||||
for _, config := range currentConfigurations {
|
for _, config := range currentConfigurations {
|
||||||
for _, frontend := range config.Frontends {
|
for _, frontend := range config.Frontends {
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ func (server *Server) postLoadConfiguration() {
|
||||||
// and is configured with ACME
|
// and is configured with ACME
|
||||||
ACMEEnabled := false
|
ACMEEnabled := false
|
||||||
for _, entryPoint := range frontend.EntryPoints {
|
for _, entryPoint := range frontend.EntryPoints {
|
||||||
if server.globalConfiguration.ACME.EntryPoint == entryPoint && server.globalConfiguration.EntryPoints[entryPoint].TLS != nil {
|
if s.globalConfiguration.ACME.EntryPoint == entryPoint && s.globalConfiguration.EntryPoints[entryPoint].TLS != nil {
|
||||||
ACMEEnabled = true
|
ACMEEnabled = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,7 @@ func (server *Server) postLoadConfiguration() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error parsing domains: %v", err)
|
log.Errorf("Error parsing domains: %v", err)
|
||||||
} else {
|
} else {
|
||||||
server.globalConfiguration.ACME.LoadCertificateForDomains(domains)
|
s.globalConfiguration.ACME.LoadCertificateForDomains(domains)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,65 +511,65 @@ func (server *Server) postLoadConfiguration() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) configureProviders() {
|
func (s *Server) configureProviders() {
|
||||||
// configure providers
|
// configure providers
|
||||||
if server.globalConfiguration.Docker != nil {
|
if s.globalConfiguration.Docker != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Docker)
|
s.providers = append(s.providers, s.globalConfiguration.Docker)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Marathon != nil {
|
if s.globalConfiguration.Marathon != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Marathon)
|
s.providers = append(s.providers, s.globalConfiguration.Marathon)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.File != nil {
|
if s.globalConfiguration.File != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.File)
|
s.providers = append(s.providers, s.globalConfiguration.File)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Rest != nil {
|
if s.globalConfiguration.Rest != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Rest)
|
s.providers = append(s.providers, s.globalConfiguration.Rest)
|
||||||
server.globalConfiguration.Rest.CurrentConfigurations = &server.currentConfigurations
|
s.globalConfiguration.Rest.CurrentConfigurations = &s.currentConfigurations
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Consul != nil {
|
if s.globalConfiguration.Consul != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Consul)
|
s.providers = append(s.providers, s.globalConfiguration.Consul)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.ConsulCatalog != nil {
|
if s.globalConfiguration.ConsulCatalog != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.ConsulCatalog)
|
s.providers = append(s.providers, s.globalConfiguration.ConsulCatalog)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Etcd != nil {
|
if s.globalConfiguration.Etcd != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Etcd)
|
s.providers = append(s.providers, s.globalConfiguration.Etcd)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Zookeeper != nil {
|
if s.globalConfiguration.Zookeeper != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Zookeeper)
|
s.providers = append(s.providers, s.globalConfiguration.Zookeeper)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Boltdb != nil {
|
if s.globalConfiguration.Boltdb != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Boltdb)
|
s.providers = append(s.providers, s.globalConfiguration.Boltdb)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Kubernetes != nil {
|
if s.globalConfiguration.Kubernetes != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Kubernetes)
|
s.providers = append(s.providers, s.globalConfiguration.Kubernetes)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Mesos != nil {
|
if s.globalConfiguration.Mesos != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Mesos)
|
s.providers = append(s.providers, s.globalConfiguration.Mesos)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Eureka != nil {
|
if s.globalConfiguration.Eureka != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Eureka)
|
s.providers = append(s.providers, s.globalConfiguration.Eureka)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.ECS != nil {
|
if s.globalConfiguration.ECS != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.ECS)
|
s.providers = append(s.providers, s.globalConfiguration.ECS)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.Rancher != nil {
|
if s.globalConfiguration.Rancher != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.Rancher)
|
s.providers = append(s.providers, s.globalConfiguration.Rancher)
|
||||||
}
|
}
|
||||||
if server.globalConfiguration.DynamoDB != nil {
|
if s.globalConfiguration.DynamoDB != nil {
|
||||||
server.providers = append(server.providers, server.globalConfiguration.DynamoDB)
|
s.providers = append(s.providers, s.globalConfiguration.DynamoDB)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) startProviders() {
|
func (s *Server) startProviders() {
|
||||||
// start providers
|
// start providers
|
||||||
for _, p := range server.providers {
|
for _, p := range s.providers {
|
||||||
providerType := reflect.TypeOf(p)
|
providerType := reflect.TypeOf(p)
|
||||||
jsonConf, _ := json.Marshal(p)
|
jsonConf, _ := json.Marshal(p)
|
||||||
log.Infof("Starting provider %v %s", providerType, jsonConf)
|
log.Infof("Starting provider %v %s", providerType, jsonConf)
|
||||||
currentProvider := p
|
currentProvider := p
|
||||||
safe.Go(func() {
|
safe.Go(func() {
|
||||||
err := currentProvider.Provide(server.configurationChan, server.routinesPool, server.globalConfiguration.Constraints)
|
err := currentProvider.Provide(s.configurationChan, s.routinesPool, s.globalConfiguration.Constraints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error starting provider %v: %s", providerType, err)
|
log.Errorf("Error starting provider %v: %s", providerType, err)
|
||||||
}
|
}
|
||||||
|
@ -610,7 +610,7 @@ func createClientTLSConfig(entryPointName string, tlsOption *traefikTls.TLS) (*t
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a TLS config that allows terminating HTTPS for multiple domains using SNI
|
// creates a TLS config that allows terminating HTTPS for multiple domains using SNI
|
||||||
func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikTls.TLS, router *middlewares.HandlerSwitcher) (*tls.Config, error) {
|
func (s *Server) createTLSConfig(entryPointName string, tlsOption *traefikTls.TLS, router *middlewares.HandlerSwitcher) (*tls.Config, error) {
|
||||||
if tlsOption == nil {
|
if tlsOption == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -625,7 +625,7 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikT
|
||||||
} else {
|
} else {
|
||||||
*epDomainsCertificatesTmp = make(map[string]*tls.Certificate)
|
*epDomainsCertificatesTmp = make(map[string]*tls.Certificate)
|
||||||
}
|
}
|
||||||
server.serverEntryPoints[entryPointName].certs.Set(epDomainsCertificatesTmp)
|
s.serverEntryPoints[entryPointName].certs.Set(epDomainsCertificatesTmp)
|
||||||
// ensure http2 enabled
|
// ensure http2 enabled
|
||||||
config.NextProtos = []string{"h2", "http/1.1"}
|
config.NextProtos = []string{"h2", "http/1.1"}
|
||||||
|
|
||||||
|
@ -654,9 +654,9 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.globalConfiguration.ACME != nil {
|
if s.globalConfiguration.ACME != nil {
|
||||||
if _, ok := server.serverEntryPoints[server.globalConfiguration.ACME.EntryPoint]; ok {
|
if _, ok := s.serverEntryPoints[s.globalConfiguration.ACME.EntryPoint]; ok {
|
||||||
if entryPointName == server.globalConfiguration.ACME.EntryPoint {
|
if entryPointName == s.globalConfiguration.ACME.EntryPoint {
|
||||||
checkOnDemandDomain := func(domain string) bool {
|
checkOnDemandDomain := func(domain string) bool {
|
||||||
routeMatch := &mux.RouteMatch{}
|
routeMatch := &mux.RouteMatch{}
|
||||||
router := router.GetHandler()
|
router := router.GetHandler()
|
||||||
|
@ -666,23 +666,23 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikT
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if server.leadership == nil {
|
if s.leadership == nil {
|
||||||
err := server.globalConfiguration.ACME.CreateLocalConfig(config, &server.serverEntryPoints[entryPointName].certs, checkOnDemandDomain)
|
err := s.globalConfiguration.ACME.CreateLocalConfig(config, &s.serverEntryPoints[entryPointName].certs, checkOnDemandDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := server.globalConfiguration.ACME.CreateClusterConfig(server.leadership, config, &server.serverEntryPoints[entryPointName].certs, checkOnDemandDomain)
|
err := s.globalConfiguration.ACME.CreateClusterConfig(s.leadership, config, &s.serverEntryPoints[entryPointName].certs, checkOnDemandDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Unknown entrypoint " + server.globalConfiguration.ACME.EntryPoint + " for ACME configuration")
|
return nil, errors.New("Unknown entrypoint " + s.globalConfiguration.ACME.EntryPoint + " for ACME configuration")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config.GetCertificate = server.serverEntryPoints[entryPointName].getCertificate
|
config.GetCertificate = s.serverEntryPoints[entryPointName].getCertificate
|
||||||
}
|
}
|
||||||
if len(config.Certificates) == 0 {
|
if len(config.Certificates) == 0 {
|
||||||
return nil, errors.New("No certificates found for TLS entrypoint " + entryPointName)
|
return nil, errors.New("No certificates found for TLS entrypoint " + entryPointName)
|
||||||
|
@ -691,15 +691,15 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikT
|
||||||
// in each certificate and populates the config.NameToCertificate map.
|
// in each certificate and populates the config.NameToCertificate map.
|
||||||
config.BuildNameToCertificate()
|
config.BuildNameToCertificate()
|
||||||
//Set the minimum TLS version if set in the config TOML
|
//Set the minimum TLS version if set in the config TOML
|
||||||
if minConst, exists := traefikTls.MinVersion[server.globalConfiguration.EntryPoints[entryPointName].TLS.MinVersion]; exists {
|
if minConst, exists := traefikTls.MinVersion[s.globalConfiguration.EntryPoints[entryPointName].TLS.MinVersion]; exists {
|
||||||
config.PreferServerCipherSuites = true
|
config.PreferServerCipherSuites = true
|
||||||
config.MinVersion = minConst
|
config.MinVersion = minConst
|
||||||
}
|
}
|
||||||
//Set the list of CipherSuites if set in the config TOML
|
//Set the list of CipherSuites if set in the config TOML
|
||||||
if server.globalConfiguration.EntryPoints[entryPointName].TLS.CipherSuites != nil {
|
if s.globalConfiguration.EntryPoints[entryPointName].TLS.CipherSuites != nil {
|
||||||
//if our list of CipherSuites is defined in the entrypoint config, we can re-initilize the suites list as empty
|
//if our list of CipherSuites is defined in the entrypoint config, we can re-initilize the suites list as empty
|
||||||
config.CipherSuites = make([]uint16, 0)
|
config.CipherSuites = make([]uint16, 0)
|
||||||
for _, cipher := range server.globalConfiguration.EntryPoints[entryPointName].TLS.CipherSuites {
|
for _, cipher := range s.globalConfiguration.EntryPoints[entryPointName].TLS.CipherSuites {
|
||||||
if cipherConst, exists := traefikTls.CipherSuites[cipher]; exists {
|
if cipherConst, exists := traefikTls.CipherSuites[cipher]; exists {
|
||||||
config.CipherSuites = append(config.CipherSuites, cipherConst)
|
config.CipherSuites = append(config.CipherSuites, cipherConst)
|
||||||
} else {
|
} else {
|
||||||
|
@ -711,7 +711,7 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *traefikT
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) startServer(serverEntryPoint *serverEntryPoint, globalConfiguration configuration.GlobalConfiguration) {
|
func (s *Server) startServer(serverEntryPoint *serverEntryPoint, globalConfiguration configuration.GlobalConfiguration) {
|
||||||
log.Infof("Starting server on %s", serverEntryPoint.httpServer.Addr)
|
log.Infof("Starting server on %s", serverEntryPoint.httpServer.Addr)
|
||||||
var err error
|
var err error
|
||||||
if serverEntryPoint.httpServer.TLSConfig != nil {
|
if serverEntryPoint.httpServer.TLSConfig != nil {
|
||||||
|
@ -724,28 +724,28 @@ func (server *Server) startServer(serverEntryPoint *serverEntryPoint, globalConf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) addInternalRoutes(entryPointName string, router *mux.Router) {
|
func (s *Server) addInternalRoutes(entryPointName string, router *mux.Router) {
|
||||||
if server.globalConfiguration.Metrics != nil && server.globalConfiguration.Metrics.Prometheus != nil && server.globalConfiguration.Metrics.Prometheus.EntryPoint == entryPointName {
|
if s.globalConfiguration.Metrics != nil && s.globalConfiguration.Metrics.Prometheus != nil && s.globalConfiguration.Metrics.Prometheus.EntryPoint == entryPointName {
|
||||||
metrics.PrometheusHandler{}.AddRoutes(router)
|
metrics.PrometheusHandler{}.AddRoutes(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.globalConfiguration.Rest != nil && server.globalConfiguration.Rest.EntryPoint == entryPointName {
|
if s.globalConfiguration.Rest != nil && s.globalConfiguration.Rest.EntryPoint == entryPointName {
|
||||||
server.globalConfiguration.Rest.AddRoutes(router)
|
s.globalConfiguration.Rest.AddRoutes(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.globalConfiguration.API != nil && server.globalConfiguration.API.EntryPoint == entryPointName {
|
if s.globalConfiguration.API != nil && s.globalConfiguration.API.EntryPoint == entryPointName {
|
||||||
server.globalConfiguration.API.AddRoutes(router)
|
s.globalConfiguration.API.AddRoutes(router)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) addInternalPublicRoutes(entryPointName string, router *mux.Router) {
|
func (s *Server) addInternalPublicRoutes(entryPointName string, router *mux.Router) {
|
||||||
if server.globalConfiguration.Ping != nil && server.globalConfiguration.Ping.EntryPoint != "" && server.globalConfiguration.Ping.EntryPoint == entryPointName {
|
if s.globalConfiguration.Ping != nil && s.globalConfiguration.Ping.EntryPoint != "" && s.globalConfiguration.Ping.EntryPoint == entryPointName {
|
||||||
server.globalConfiguration.Ping.AddRoutes(router)
|
s.globalConfiguration.Ping.AddRoutes(router)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) prepareServer(entryPointName string, entryPoint *configuration.EntryPoint, router *middlewares.HandlerSwitcher, middlewares []negroni.Handler, internalMiddlewares []negroni.Handler) (*http.Server, net.Listener, error) {
|
func (s *Server) prepareServer(entryPointName string, entryPoint *configuration.EntryPoint, router *middlewares.HandlerSwitcher, middlewares []negroni.Handler, internalMiddlewares []negroni.Handler) (*http.Server, net.Listener, error) {
|
||||||
readTimeout, writeTimeout, idleTimeout := buildServerTimeouts(server.globalConfiguration)
|
readTimeout, writeTimeout, idleTimeout := buildServerTimeouts(s.globalConfiguration)
|
||||||
log.Infof("Preparing server %s %+v with readTimeout=%s writeTimeout=%s idleTimeout=%s", entryPointName, entryPoint, readTimeout, writeTimeout, idleTimeout)
|
log.Infof("Preparing server %s %+v with readTimeout=%s writeTimeout=%s idleTimeout=%s", entryPointName, entryPoint, readTimeout, writeTimeout, idleTimeout)
|
||||||
|
|
||||||
// middlewares
|
// middlewares
|
||||||
|
@ -756,14 +756,14 @@ func (server *Server) prepareServer(entryPointName string, entryPoint *configura
|
||||||
n.UseHandler(router)
|
n.UseHandler(router)
|
||||||
|
|
||||||
path := "/"
|
path := "/"
|
||||||
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Path != "" {
|
if s.globalConfiguration.Web != nil && s.globalConfiguration.Web.Path != "" {
|
||||||
path = server.globalConfiguration.Web.Path
|
path = s.globalConfiguration.Web.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
internalMuxRouter := server.buildInternalRouter(entryPointName, path, internalMiddlewares)
|
internalMuxRouter := s.buildInternalRouter(entryPointName, path, internalMiddlewares)
|
||||||
internalMuxRouter.NotFoundHandler = n
|
internalMuxRouter.NotFoundHandler = n
|
||||||
|
|
||||||
tlsConfig, err := server.createTLSConfig(entryPointName, entryPoint.TLS, router)
|
tlsConfig, err := s.createTLSConfig(entryPointName, entryPoint.TLS, router)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error creating TLS config: %s", err)
|
log.Errorf("Error creating TLS config: %s", err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -806,7 +806,7 @@ func (server *Server) prepareServer(entryPointName string, entryPoint *configura
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildInternalRouter(entryPointName, path string, internalMiddlewares []negroni.Handler) *mux.Router {
|
func (s *Server) buildInternalRouter(entryPointName, path string, internalMiddlewares []negroni.Handler) *mux.Router {
|
||||||
internalMuxRouter := mux.NewRouter()
|
internalMuxRouter := mux.NewRouter()
|
||||||
internalMuxRouter.StrictSlash(true)
|
internalMuxRouter.StrictSlash(true)
|
||||||
internalMuxRouter.SkipClean(true)
|
internalMuxRouter.SkipClean(true)
|
||||||
|
@ -815,10 +815,10 @@ func (server *Server) buildInternalRouter(entryPointName, path string, internalM
|
||||||
internalMuxSubrouter.StrictSlash(true)
|
internalMuxSubrouter.StrictSlash(true)
|
||||||
internalMuxSubrouter.SkipClean(true)
|
internalMuxSubrouter.SkipClean(true)
|
||||||
|
|
||||||
server.addInternalRoutes(entryPointName, internalMuxSubrouter)
|
s.addInternalRoutes(entryPointName, internalMuxSubrouter)
|
||||||
internalMuxRouter.Walk(wrapRoute(internalMiddlewares))
|
internalMuxRouter.Walk(wrapRoute(internalMiddlewares))
|
||||||
|
|
||||||
server.addInternalPublicRoutes(entryPointName, internalMuxSubrouter)
|
s.addInternalPublicRoutes(entryPointName, internalMuxSubrouter)
|
||||||
return internalMuxRouter
|
return internalMuxRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,10 +852,10 @@ func buildServerTimeouts(globalConfig configuration.GlobalConfiguration) (readTi
|
||||||
return readTimeout, writeTimeout, idleTimeout
|
return readTimeout, writeTimeout, idleTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildEntryPoints(globalConfiguration configuration.GlobalConfiguration) map[string]*serverEntryPoint {
|
func (s *Server) buildEntryPoints(globalConfiguration configuration.GlobalConfiguration) map[string]*serverEntryPoint {
|
||||||
serverEntryPoints := make(map[string]*serverEntryPoint)
|
serverEntryPoints := make(map[string]*serverEntryPoint)
|
||||||
for entryPointName := range globalConfiguration.EntryPoints {
|
for entryPointName := range globalConfiguration.EntryPoints {
|
||||||
router := server.buildDefaultHTTPRouter()
|
router := s.buildDefaultHTTPRouter()
|
||||||
serverEntryPoints[entryPointName] = &serverEntryPoint{
|
serverEntryPoints[entryPointName] = &serverEntryPoint{
|
||||||
httpRouter: middlewares.NewHandlerSwitcher(router),
|
httpRouter: middlewares.NewHandlerSwitcher(router),
|
||||||
}
|
}
|
||||||
|
@ -865,7 +865,7 @@ func (server *Server) buildEntryPoints(globalConfiguration configuration.GlobalC
|
||||||
|
|
||||||
// getRoundTripper will either use server.defaultForwardingRoundTripper or create a new one
|
// getRoundTripper will either use server.defaultForwardingRoundTripper or create a new one
|
||||||
// given a custom TLS configuration is passed and the passTLSCert option is set to true.
|
// given a custom TLS configuration is passed and the passTLSCert option is set to true.
|
||||||
func (server *Server) getRoundTripper(entryPointName string, globalConfiguration configuration.GlobalConfiguration, passTLSCert bool, tls *traefikTls.TLS) (http.RoundTripper, error) {
|
func (s *Server) getRoundTripper(entryPointName string, globalConfiguration configuration.GlobalConfiguration, passTLSCert bool, tls *traefikTls.TLS) (http.RoundTripper, error) {
|
||||||
if passTLSCert {
|
if passTLSCert {
|
||||||
tlsConfig, err := createClientTLSConfig(entryPointName, tls)
|
tlsConfig, err := createClientTLSConfig(entryPointName, tls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -878,13 +878,13 @@ func (server *Server) getRoundTripper(entryPointName string, globalConfiguration
|
||||||
return transport, nil
|
return transport, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return server.defaultForwardingRoundTripper, nil
|
return s.defaultForwardingRoundTripper, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig returns a new gorilla.mux Route from the specified global configuration and the dynamic
|
// LoadConfig returns a new gorilla.mux Route from the specified global configuration and the dynamic
|
||||||
// provider configurations.
|
// provider configurations.
|
||||||
func (server *Server) loadConfig(configurations types.Configurations, globalConfiguration configuration.GlobalConfiguration) (map[string]*serverEntryPoint, error) {
|
func (s *Server) loadConfig(configurations types.Configurations, globalConfiguration configuration.GlobalConfiguration) (map[string]*serverEntryPoint, error) {
|
||||||
serverEntryPoints := server.buildEntryPoints(globalConfiguration)
|
serverEntryPoints := s.buildEntryPoints(globalConfiguration)
|
||||||
redirectHandlers := make(map[string]negroni.Handler)
|
redirectHandlers := make(map[string]negroni.Handler)
|
||||||
backends := map[string]http.Handler{}
|
backends := map[string]http.Handler{}
|
||||||
backendsHealthCheck := map[string]*healthcheck.BackendHealthCheck{}
|
backendsHealthCheck := map[string]*healthcheck.BackendHealthCheck{}
|
||||||
|
@ -928,12 +928,12 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
if entryPoint.Redirect != nil {
|
if entryPoint.Redirect != nil {
|
||||||
if redirectHandlers[entryPointName] != nil {
|
if redirectHandlers[entryPointName] != nil {
|
||||||
n.Use(redirectHandlers[entryPointName])
|
n.Use(redirectHandlers[entryPointName])
|
||||||
} else if handler, err := server.loadEntryPointConfig(entryPointName, entryPoint); err != nil {
|
} else if handler, err := s.loadEntryPointConfig(entryPointName, entryPoint); err != nil {
|
||||||
log.Errorf("Error loading entrypoint configuration for frontend %s: %v", frontendName, err)
|
log.Errorf("Error loading entrypoint configuration for frontend %s: %v", frontendName, err)
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
continue frontend
|
continue frontend
|
||||||
} else {
|
} else {
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
saveFrontend := accesslog.NewSaveNegroniFrontend(handler, frontendName)
|
saveFrontend := accesslog.NewSaveNegroniFrontend(handler, frontendName)
|
||||||
n.Use(saveFrontend)
|
n.Use(saveFrontend)
|
||||||
redirectHandlers[entryPointName] = saveFrontend
|
redirectHandlers[entryPointName] = saveFrontend
|
||||||
|
@ -946,7 +946,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
if backends[entryPointName+frontend.Backend] == nil {
|
if backends[entryPointName+frontend.Backend] == nil {
|
||||||
log.Debugf("Creating backend %s", frontend.Backend)
|
log.Debugf("Creating backend %s", frontend.Backend)
|
||||||
|
|
||||||
roundTripper, err := server.getRoundTripper(entryPointName, globalConfiguration, frontend.PassTLSCert, entryPoint.TLS)
|
roundTripper, err := s.getRoundTripper(entryPointName, globalConfiguration, frontend.PassTLSCert, entryPoint.TLS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to create RoundTripper for frontend %s: %v", frontendName, err)
|
log.Errorf("Failed to create RoundTripper for frontend %s: %v", frontendName, err)
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
|
@ -984,7 +984,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
|
|
||||||
var rr *roundrobin.RoundRobin
|
var rr *roundrobin.RoundRobin
|
||||||
var saveFrontend http.Handler
|
var saveFrontend http.Handler
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
saveBackend := accesslog.NewSaveBackend(fwd, frontend.Backend)
|
saveBackend := accesslog.NewSaveBackend(fwd, frontend.Backend)
|
||||||
saveFrontend = accesslog.NewSaveFrontend(saveBackend, frontendName)
|
saveFrontend = accesslog.NewSaveFrontend(saveBackend, frontendName)
|
||||||
rr, _ = roundrobin.New(saveFrontend)
|
rr, _ = roundrobin.New(saveFrontend)
|
||||||
|
@ -1029,7 +1029,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
hcOpts := parseHealthCheckOptions(rebalancer, frontend.Backend, config.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
hcOpts := parseHealthCheckOptions(rebalancer, frontend.Backend, config.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
||||||
if hcOpts != nil {
|
if hcOpts != nil {
|
||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
hcOpts.Transport = server.defaultForwardingRoundTripper
|
hcOpts.Transport = s.defaultForwardingRoundTripper
|
||||||
backendsHealthCheck[entryPointName+frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
backendsHealthCheck[entryPointName+frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
||||||
}
|
}
|
||||||
lb = middlewares.NewEmptyBackendHandler(rebalancer, lb)
|
lb = middlewares.NewEmptyBackendHandler(rebalancer, lb)
|
||||||
|
@ -1037,7 +1037,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
log.Debugf("Creating load-balancer wrr")
|
log.Debugf("Creating load-balancer wrr")
|
||||||
if sticky != nil {
|
if sticky != nil {
|
||||||
log.Debugf("Sticky session with cookie %v", cookieName)
|
log.Debugf("Sticky session with cookie %v", cookieName)
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
rr, _ = roundrobin.New(saveFrontend, roundrobin.EnableStickySession(sticky))
|
rr, _ = roundrobin.New(saveFrontend, roundrobin.EnableStickySession(sticky))
|
||||||
} else {
|
} else {
|
||||||
rr, _ = roundrobin.New(fwd, roundrobin.EnableStickySession(sticky))
|
rr, _ = roundrobin.New(fwd, roundrobin.EnableStickySession(sticky))
|
||||||
|
@ -1051,7 +1051,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, config.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
hcOpts := parseHealthCheckOptions(rr, frontend.Backend, config.Backends[frontend.Backend].HealthCheck, globalConfiguration.HealthCheck)
|
||||||
if hcOpts != nil {
|
if hcOpts != nil {
|
||||||
log.Debugf("Setting up backend health check %s", *hcOpts)
|
log.Debugf("Setting up backend health check %s", *hcOpts)
|
||||||
hcOpts.Transport = server.defaultForwardingRoundTripper
|
hcOpts.Transport = s.defaultForwardingRoundTripper
|
||||||
backendsHealthCheck[entryPointName+frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
backendsHealthCheck[entryPointName+frontend.Backend] = healthcheck.NewBackendHealthCheck(*hcOpts)
|
||||||
}
|
}
|
||||||
lb = middlewares.NewEmptyBackendHandler(rr, lb)
|
lb = middlewares.NewEmptyBackendHandler(rr, lb)
|
||||||
|
@ -1073,7 +1073,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
}
|
}
|
||||||
|
|
||||||
if frontend.RateLimit != nil && len(frontend.RateLimit.RateSet) > 0 {
|
if frontend.RateLimit != nil && len(frontend.RateLimit.RateSet) > 0 {
|
||||||
lb, err = server.buildRateLimiter(lb, frontend.RateLimit)
|
lb, err = s.buildRateLimiter(lb, frontend.RateLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error creating rate limiter: %v", err)
|
log.Errorf("Error creating rate limiter: %v", err)
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
|
@ -1100,11 +1100,11 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
|
|
||||||
if globalConfiguration.Retry != nil {
|
if globalConfiguration.Retry != nil {
|
||||||
countServers := len(config.Backends[frontend.Backend].Servers)
|
countServers := len(config.Backends[frontend.Backend].Servers)
|
||||||
lb = server.buildRetryMiddleware(lb, globalConfiguration, countServers, frontend.Backend)
|
lb = s.buildRetryMiddleware(lb, globalConfiguration, countServers, frontend.Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
if server.metricsRegistry.IsEnabled() {
|
if s.metricsRegistry.IsEnabled() {
|
||||||
n.Use(middlewares.NewMetricsWrapper(server.metricsRegistry, frontend.Backend))
|
n.Use(middlewares.NewMetricsWrapper(s.metricsRegistry, frontend.Backend))
|
||||||
}
|
}
|
||||||
|
|
||||||
ipWhitelistMiddleware, err := configureIPWhitelistMiddleware(frontend.WhitelistSourceRange)
|
ipWhitelistMiddleware, err := configureIPWhitelistMiddleware(frontend.WhitelistSourceRange)
|
||||||
|
@ -1117,11 +1117,11 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
|
|
||||||
if len(frontend.Redirect) > 0 {
|
if len(frontend.Redirect) > 0 {
|
||||||
proto := "http"
|
proto := "http"
|
||||||
if server.globalConfiguration.EntryPoints[frontend.Redirect].TLS != nil {
|
if s.globalConfiguration.EntryPoints[frontend.Redirect].TLS != nil {
|
||||||
proto = "https"
|
proto = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
regex, replacement, err := server.buildRedirect(proto, entryPoint)
|
regex, replacement, err := s.buildRedirect(proto, entryPoint)
|
||||||
rewrite, err := middlewares.NewRewrite(regex, replacement, true)
|
rewrite, err := middlewares.NewRewrite(regex, replacement, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error creating Frontend Redirect: %v", err)
|
log.Fatalf("Error creating Frontend Redirect: %v", err)
|
||||||
|
@ -1177,7 +1177,7 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
if frontend.Priority > 0 {
|
if frontend.Priority > 0 {
|
||||||
newServerRoute.route.Priority(frontend.Priority)
|
newServerRoute.route.Priority(frontend.Priority)
|
||||||
}
|
}
|
||||||
server.wireFrontendBackend(newServerRoute, backends[entryPointName+frontend.Backend])
|
s.wireFrontendBackend(newServerRoute, backends[entryPointName+frontend.Backend])
|
||||||
|
|
||||||
err := newServerRoute.route.GetError()
|
err := newServerRoute.route.GetError()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1186,10 +1186,10 @@ func (server *Server) loadConfig(configurations types.Configurations, globalConf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
healthcheck.GetHealthCheck().SetBackendsConfiguration(server.routinesPool.Ctx(), backendsHealthCheck)
|
healthcheck.GetHealthCheck().SetBackendsConfiguration(s.routinesPool.Ctx(), backendsHealthCheck)
|
||||||
// Get new certificates list sorted per entrypoints
|
// Get new certificates list sorted per entrypoints
|
||||||
// Update certificates
|
// Update certificates
|
||||||
entryPointsCertificates, err := server.loadHTTPSConfiguration(configurations)
|
entryPointsCertificates, err := s.loadHTTPSConfiguration(configurations)
|
||||||
//sort routes and update certificates
|
//sort routes and update certificates
|
||||||
for serverEntryPointName, serverEntryPoint := range serverEntryPoints {
|
for serverEntryPointName, serverEntryPoint := range serverEntryPoints {
|
||||||
serverEntryPoint.httpRouter.GetHandler().SortRoutes()
|
serverEntryPoint.httpRouter.GetHandler().SortRoutes()
|
||||||
|
@ -1233,7 +1233,7 @@ func configureIPWhitelistMiddleware(whitelistSourceRanges []string) (negroni.Han
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) wireFrontendBackend(serverRoute *serverRoute, handler http.Handler) {
|
func (s *Server) wireFrontendBackend(serverRoute *serverRoute, handler http.Handler) {
|
||||||
// path replace - This needs to always be the very last on the handler chain (first in the order in this function)
|
// path replace - This needs to always be the very last on the handler chain (first in the order in this function)
|
||||||
// -- Replacing Path should happen at the very end of the Modifier chain, after all the Matcher+Modifiers ran
|
// -- Replacing Path should happen at the very end of the Modifier chain, after all the Matcher+Modifiers ran
|
||||||
if len(serverRoute.replacePath) > 0 {
|
if len(serverRoute.replacePath) > 0 {
|
||||||
|
@ -1277,16 +1277,16 @@ func (server *Server) wireFrontendBackend(serverRoute *serverRoute, handler http
|
||||||
serverRoute.route.Handler(handler)
|
serverRoute.route.Handler(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) loadEntryPointConfig(entryPointName string, entryPoint *configuration.EntryPoint) (negroni.Handler, error) {
|
func (s *Server) loadEntryPointConfig(entryPointName string, entryPoint *configuration.EntryPoint) (negroni.Handler, error) {
|
||||||
regex := entryPoint.Redirect.Regex
|
regex := entryPoint.Redirect.Regex
|
||||||
replacement := entryPoint.Redirect.Replacement
|
replacement := entryPoint.Redirect.Replacement
|
||||||
var err error
|
var err error
|
||||||
if len(entryPoint.Redirect.EntryPoint) > 0 {
|
if len(entryPoint.Redirect.EntryPoint) > 0 {
|
||||||
var protocol = "http"
|
var protocol = "http"
|
||||||
if server.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].TLS != nil {
|
if s.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].TLS != nil {
|
||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
regex, replacement, err = server.buildRedirect(protocol, entryPoint)
|
regex, replacement, err = s.buildRedirect(protocol, entryPoint)
|
||||||
}
|
}
|
||||||
rewrite, err := middlewares.NewRewrite(regex, replacement, true)
|
rewrite, err := middlewares.NewRewrite(regex, replacement, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1297,21 +1297,21 @@ func (server *Server) loadEntryPointConfig(entryPointName string, entryPoint *co
|
||||||
return rewrite, nil
|
return rewrite, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildRedirect(protocol string, entryPoint *configuration.EntryPoint) (string, string, error) {
|
func (s *Server) buildRedirect(protocol string, entryPoint *configuration.EntryPoint) (string, string, error) {
|
||||||
regex := `^(?:https?:\/\/)?([\w\._-]+)(?::\d+)?(.*)$`
|
regex := `^(?:https?:\/\/)?([\w\._-]+)(?::\d+)?(.*)$`
|
||||||
if server.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint] == nil {
|
if s.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint] == nil {
|
||||||
return "", "", fmt.Errorf("unknown target entrypoint %q", entryPoint.Redirect.EntryPoint)
|
return "", "", fmt.Errorf("unknown target entrypoint %q", entryPoint.Redirect.EntryPoint)
|
||||||
}
|
}
|
||||||
r, _ := regexp.Compile(`(:\d+)`)
|
r, _ := regexp.Compile(`(:\d+)`)
|
||||||
match := r.FindStringSubmatch(server.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].Address)
|
match := r.FindStringSubmatch(s.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].Address)
|
||||||
if len(match) == 0 {
|
if len(match) == 0 {
|
||||||
return "", "", fmt.Errorf("bad Address format %q", server.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].Address)
|
return "", "", fmt.Errorf("bad Address format %q", s.globalConfiguration.EntryPoints[entryPoint.Redirect.EntryPoint].Address)
|
||||||
}
|
}
|
||||||
replacement := protocol + "://$1" + match[0] + "$2"
|
replacement := protocol + "://$1" + match[0] + "$2"
|
||||||
return regex, replacement, nil
|
return regex, replacement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildDefaultHTTPRouter() *mux.Router {
|
func (s *Server) buildDefaultHTTPRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
||||||
router.StrictSlash(true)
|
router.StrictSlash(true)
|
||||||
|
@ -1365,11 +1365,11 @@ func sortedFrontendNamesForConfig(configuration *types.Configuration) []string {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) configureFrontends(frontends map[string]*types.Frontend) {
|
func (s *Server) configureFrontends(frontends map[string]*types.Frontend) {
|
||||||
for _, frontend := range frontends {
|
for _, frontend := range frontends {
|
||||||
// default endpoints if not defined in frontends
|
// default endpoints if not defined in frontends
|
||||||
if len(frontend.EntryPoints) == 0 {
|
if len(frontend.EntryPoints) == 0 {
|
||||||
frontend.EntryPoints = server.globalConfiguration.DefaultEntryPoints
|
frontend.EntryPoints = s.globalConfiguration.DefaultEntryPoints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1411,7 +1411,7 @@ func (*Server) configureBackends(backends map[string]*types.Backend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) registerMetricClients(metricsConfig *types.Metrics) {
|
func (s *Server) registerMetricClients(metricsConfig *types.Metrics) {
|
||||||
registries := []metrics.Registry{}
|
registries := []metrics.Registry{}
|
||||||
|
|
||||||
if metricsConfig.Prometheus != nil {
|
if metricsConfig.Prometheus != nil {
|
||||||
|
@ -1432,7 +1432,7 @@ func (server *Server) registerMetricClients(metricsConfig *types.Metrics) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(registries) > 0 {
|
if len(registries) > 0 {
|
||||||
server.metricsRegistry = metrics.NewMultiRegistry(registries)
|
s.metricsRegistry = metrics.NewMultiRegistry(registries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1442,7 +1442,7 @@ func stopMetricsClients() {
|
||||||
metrics.StopInfluxDB()
|
metrics.StopInfluxDB()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildRateLimiter(handler http.Handler, rlConfig *types.RateLimit) (http.Handler, error) {
|
func (s *Server) buildRateLimiter(handler http.Handler, rlConfig *types.RateLimit) (http.Handler, error) {
|
||||||
extractFunc, err := utils.NewExtractor(rlConfig.ExtractorFunc)
|
extractFunc, err := utils.NewExtractor(rlConfig.ExtractorFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1457,12 +1457,12 @@ func (server *Server) buildRateLimiter(handler http.Handler, rlConfig *types.Rat
|
||||||
return ratelimit.New(handler, extractFunc, rateSet)
|
return ratelimit.New(handler, extractFunc, rateSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) buildRetryMiddleware(handler http.Handler, globalConfig configuration.GlobalConfiguration, countServers int, backendName string) http.Handler {
|
func (s *Server) buildRetryMiddleware(handler http.Handler, globalConfig configuration.GlobalConfiguration, countServers int, backendName string) http.Handler {
|
||||||
retryListeners := middlewares.RetryListeners{}
|
retryListeners := middlewares.RetryListeners{}
|
||||||
if server.metricsRegistry.IsEnabled() {
|
if s.metricsRegistry.IsEnabled() {
|
||||||
retryListeners = append(retryListeners, middlewares.NewMetricsRetryListener(server.metricsRegistry, backendName))
|
retryListeners = append(retryListeners, middlewares.NewMetricsRetryListener(s.metricsRegistry, backendName))
|
||||||
}
|
}
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
retryListeners = append(retryListeners, &accesslog.SaveRetries{})
|
retryListeners = append(retryListeners, &accesslog.SaveRetries{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,19 +10,19 @@ import (
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (server *Server) configureSignals() {
|
func (s *Server) configureSignals() {
|
||||||
signal.Notify(server.signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
|
signal.Notify(s.signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) listenSignals() {
|
func (s *Server) listenSignals() {
|
||||||
for {
|
for {
|
||||||
sig := <-server.signals
|
sig := <-s.signals
|
||||||
switch sig {
|
switch sig {
|
||||||
case syscall.SIGUSR1:
|
case syscall.SIGUSR1:
|
||||||
log.Infof("Closing and re-opening log files for rotation: %+v", sig)
|
log.Infof("Closing and re-opening log files for rotation: %+v", sig)
|
||||||
|
|
||||||
if server.accessLoggerMiddleware != nil {
|
if s.accessLoggerMiddleware != nil {
|
||||||
if err := server.accessLoggerMiddleware.Rotate(); err != nil {
|
if err := s.accessLoggerMiddleware.Rotate(); err != nil {
|
||||||
log.Errorf("Error rotating access log: %s", err)
|
log.Errorf("Error rotating access log: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,13 @@ func (server *Server) listenSignals() {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Infof("I have to go... %+v", sig)
|
log.Infof("I have to go... %+v", sig)
|
||||||
reqAcceptGraceTimeOut := time.Duration(server.globalConfiguration.LifeCycle.RequestAcceptGraceTimeout)
|
reqAcceptGraceTimeOut := time.Duration(s.globalConfiguration.LifeCycle.RequestAcceptGraceTimeout)
|
||||||
if reqAcceptGraceTimeOut > 0 {
|
if reqAcceptGraceTimeOut > 0 {
|
||||||
log.Infof("Waiting %s for incoming requests to cease", reqAcceptGraceTimeOut)
|
log.Infof("Waiting %s for incoming requests to cease", reqAcceptGraceTimeOut)
|
||||||
time.Sleep(reqAcceptGraceTimeOut)
|
time.Sleep(reqAcceptGraceTimeOut)
|
||||||
}
|
}
|
||||||
log.Info("Stopping server gracefully")
|
log.Info("Stopping server gracefully")
|
||||||
server.Stop()
|
s.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,18 @@ import (
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (server *Server) configureSignals() {
|
func (s *Server) configureSignals() {
|
||||||
signal.Notify(server.signals, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(s.signals, syscall.SIGINT, syscall.SIGTERM)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) listenSignals() {
|
func (s *Server) listenSignals() {
|
||||||
for {
|
for {
|
||||||
sig := <-server.signals
|
sig := <-s.signals
|
||||||
switch sig {
|
switch sig {
|
||||||
default:
|
default:
|
||||||
log.Infof("I have to go... %+v", sig)
|
log.Infof("I have to go... %+v", sig)
|
||||||
log.Info("Stopping server")
|
log.Info("Stopping server")
|
||||||
server.Stop()
|
s.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue