From 9087d8e18b55b16c6eefb516946d8128ec67b4b2 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Fri, 4 Oct 2024 01:06:00 +0900 Subject: [PATCH] Request consul in prestart hook --- jobs/fastcgi.nomad | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/jobs/fastcgi.nomad b/jobs/fastcgi.nomad index 56b4e27..5dd4d97 100644 --- a/jobs/fastcgi.nomad +++ b/jobs/fastcgi.nomad @@ -30,18 +30,23 @@ job "fastcgi" { sidecar = false } - driver = "exec" + driver = "docker" config { - command = "sh" + image = "busybox:1.28" + command = "sh" + network_mode = "host" args = [ "-c", - format( - "while ! ncat --send-only %s %s < /dev/null; do sleep 1; done", - local.main ? "127.0.0.1" : NOMAD_UPSTREAM_IP_mysql, - local.main ? "3306" : NOMAD_UPSTREAM_PORT_mysql - ), + local.main ? "while ! ncat --send-only 127.0.0.1 3306 < /dev/null; do sleep 1; done" + : true ? "echo -n 'Waiting for service'; until -z ${var.main_nomad_addr} 3306 < /dev/null; do echo '.'; sleep 2; done" + : "echo -n 'Waiting for service'; until nslookup mysql.service.consul 127.0.0.1:8600 2>&1 >/dev/null; do echo '.'; sleep 2; done", ] } + + resources { + cpu = 100 + memory = 100 + } } task "wait-for-memcached" { @@ -50,17 +55,24 @@ job "fastcgi" { sidecar = false } - driver = "exec" + driver = "docker" config { - command = "sh" + image = "busybox:1.28" + command = "sh" + network_mode = "host" args = [ "-c", - format("while ! ncat --send-only %s %s < /dev/null; do sleep 1; done", - local.main ? "127.0.0.1" : NOMAD_UPSTREAM_IP_memcached, - local.main ? "11211" : NOMAD_UPSTREAM_PORT_memcached - ), + local.main ? format("while ! ncat --send-only %s %s < /dev/null; do sleep 1; done", + "127.0.0.1", + "11211" + ) : "echo -n 'Waiting for service'; until nslookup memcached.service.consul 127.0.0.1:8600 2>&1 >/dev/null; do echo '.'; sleep 2; done", ] } + + resources { + cpu = 100 + memory = 100 + } } task "fastcgi" {