From ac0a211f4c53204b357f279ee1b1218a87547b87 Mon Sep 17 00:00:00 2001 From: Graham Land Date: Sun, 23 Sep 2018 21:21:45 +0100 Subject: [PATCH] nomad updates --- conf/nginx.ctpl | 2 +- nomad_job.hcl | 62 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/conf/nginx.ctpl b/conf/nginx.ctpl index a203ace..e4a1c5f 100644 --- a/conf/nginx.ctpl +++ b/conf/nginx.ctpl @@ -1,5 +1,5 @@ upstream goapp { - {{range services}}{{if .Name | regexMatch "goapp*"}}{{range service .Name}} + {{range services}}{{if .Name | regexMatch "webpagecounter*"}}{{range service .Name}} server {{.Address}}:{{.Port}} max_fails=3 fail_timeout=60 weight=1; {{end}}{{end}} {{else}}server 127.0.0.1:65535; # force a 502{{end}} } diff --git a/nomad_job.hcl b/nomad_job.hcl index 3c33aba..36c9133 100644 --- a/nomad_job.hcl +++ b/nomad_job.hcl @@ -1,9 +1,59 @@ job "webpagecounter" { datacenters = ["dc1"] type = "service" - group "webcountergroup" { - count = 4 - task "deploy-webcounters" { + + + + group "webcountergroup-a" { + constraint { + distinct_hosts = true + } + count = 2 + task "deploy-webcounters-a" { + driver = "raw_exec" + config { + command = "/usr/local/bin/webcounter" + args = ["-port=${NOMAD_PORT_http}", "-ip=0.0.0.0","-templates=/usr/local/bin/templates/*.html"] + } + resources { + cpu = 20 + memory = 60 + network { + port "http" {} + } + } + + + service { + name = "webpagecounter" + port = "http" + check { + name = "health-check-webpagecounter-${NOMAD_PORT_http}" + type = "http" + path = "/health" + interval = "10s" + timeout = "2s" + } + check { + type = "script" + name = "scripted-check-webpagecounter-${NOMAD_PORT_http}" + command = "/usr/local/bin/consul_goapp_verify.sh" + args = ["http://127.0.0.1:${NOMAD_PORT_http}/health"] + interval = "60s" + timeout = "5s" + + check_restart { + limit = 3 + grace = "90s" + ignore_warnings = false + } + } + } + } + } + group "webcountergroup-b" { + count = 3 + task "deploy-webcounters-b" { driver = "raw_exec" config { command = "/usr/local/bin/webcounter" @@ -19,10 +69,10 @@ job "webpagecounter" { service { - name = "goapp-${NOMAD_PORT_http}" + name = "webpagecounter" port = "http" check { - name = "http-check-goapp-${NOMAD_PORT_http}" + name = "health-check-webpagecounter-${NOMAD_PORT_http}" type = "http" path = "/health" interval = "10s" @@ -30,7 +80,7 @@ job "webpagecounter" { } check { type = "script" - name = "api-check-goapp-${NOMAD_PORT_http}" + name = "scripted-check-webpagecounter-${NOMAD_PORT_http}" command = "/usr/local/bin/consul_goapp_verify.sh" args = ["http://127.0.0.1:${NOMAD_PORT_http}/health"] interval = "60s"