diff --git a/Dockerfile.build b/Dockerfile.build index 210e9174..25c66f7b 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,6 +1,6 @@ FROM golang:1.6-alpine -RUN apk add -U git make -RUN go get github.com/tools/godep +RUN apk add -U git make curl +RUN go get github.com/Masterminds/glide ENV DOCKER_VERSION 1.10.3 ENV APP interlock ENV REPO ehazlett/$APP diff --git a/ext/lb/nginx/config.go b/ext/lb/nginx/config.go index 2b6085bc..f29281a3 100644 --- a/ext/lb/nginx/config.go +++ b/ext/lb/nginx/config.go @@ -32,6 +32,8 @@ type Host struct { Upstream *Upstream WebsocketEndpoints []string IPHash bool + Check string + CheckInterval int } type Config struct { Hosts []*Host diff --git a/ext/lb/nginx/generate.go b/ext/lb/nginx/generate.go index ca21be0c..dd178e51 100644 --- a/ext/lb/nginx/generate.go +++ b/ext/lb/nginx/generate.go @@ -12,6 +12,8 @@ import ( func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Container) (interface{}, error) { var hosts []*Host upstreamServers := map[string][]string{} + hostChecks := map[string]string{} + hostCheckIntervals := map[string]int{} serverNames := map[string][]string{} hostContextRoots := map[string]*ContextRoot{} hostContextRootRewrites := map[string]bool{} @@ -59,12 +61,35 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai } hostContextRootRewrites[domain] = utils.ContextRootRewrite(cInfo.Config) + // check if the first server name is there; if not, add // this happens if there are multiple backend containers if _, ok := serverNames[domain]; !ok { serverNames[domain] = []string{domain} } + healthCheck := utils.HealthCheck(cInfo.Config) + healthCheckInterval, err := utils.HealthCheckInterval(cInfo.Config) + if err != nil { + log().Errorf("error parsing health check interval: %s", err) + continue + } + + if healthCheck != "" { + if val, ok := hostChecks[domain]; ok { + // check existing host check for different values + if val != healthCheck { + log().Warnf("conflicting check specified for %s", domain) + } + } else { + hostChecks[domain] = healthCheck + hostCheckIntervals[domain] = healthCheckInterval + log().Debugf("using custom check for %s: %s", domain, healthCheck) + } + + log().Debugf("check interval for %s: %d", domain, healthCheckInterval) + } + hostSSL[domain] = utils.SSLEnabled(cInfo.Config) hostSSLOnly[domain] = utils.SSLOnly(cInfo.Config) hostIPHash[domain] = utils.IPHash(cInfo.Config) @@ -159,6 +184,8 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai Port: p.cfg.Port, ContextRoot: hostContextRoots[k], ContextRootRewrite: hostContextRootRewrites[k], + Check: hostChecks[k], + CheckInterval: hostCheckIntervals[k], SSLPort: p.cfg.SSLPort, SSL: hostSSL[k], SSLCert: hostSSLCert[k], @@ -183,6 +210,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai Name: k, Servers: servers, } + h.Upstream = up hosts = append(hosts, h) diff --git a/ext/lb/utils/health_check.go b/ext/lb/utils/health_check.go index 10cd64d9..d09e5b05 100644 --- a/ext/lb/utils/health_check.go +++ b/ext/lb/utils/health_check.go @@ -8,7 +8,7 @@ import ( ) const ( - DefaultHealthCheckInterval = 5000 + DefaultHealthCheckInterval = 10000 ) func HealthCheck(config *dockerclient.ContainerConfig) string {