From d5b492b5b425c6d07419fd52e50ad60c9a9c9f53 Mon Sep 17 00:00:00 2001 From: Bruce Becker Date: Sun, 9 Apr 2023 09:19:25 +0200 Subject: [PATCH] fix(grafana): add a pre-start job to wait for db (#21) Closed #19 Signed-off-by: Bruce Becker --- grafana.nomad | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/grafana.nomad b/grafana.nomad index 9fd0c1b..86d1cff 100644 --- a/grafana.nomad +++ b/grafana.nomad @@ -4,6 +4,12 @@ variable "grafana_version" { description = "Grafana version" } +variable "grafana_admin_password" { + type = string + sensitive = true + description = "Password for the grafana admin interface" +} + // locals { // grafana_arm = "https://dl.grafana.com/oss/release/grafana-${var.grafana_version}.linux-armv6.tar.gz" // grafana_64 = "https://dl.grafana.com/oss/release/grafana-${var.grafana_version}.linux-arm64.tar.gz" @@ -31,8 +37,8 @@ job "dashboard" { update { max_parallel = 1 min_healthy_time = "20s" - healthy_deadline = "20m" - progress_deadline = "30m" + healthy_deadline = "5m" + progress_deadline = "10m" auto_revert = true auto_promote = true canary = 1 @@ -55,7 +61,7 @@ job "dashboard" { } service { name = "mysql" - tags = ["db", "dashboard"] + tags = ["db", "dashboard", "urlprefix-/mysql:3306 proto=tcp"] port = "mysql_server" check { @@ -95,7 +101,7 @@ job "dashboard" { group "grafana" { - count = 1 + count = 2 network { port "grafana_server" { to = 3000 @@ -105,7 +111,7 @@ job "dashboard" { service { name = "grafana" - tags = ["monitoring", "dashboard", "urlprefix-/grafana"] + tags = ["monitoring", "dashboard", "urlprefix-/grafana:3000"] port = "grafana_server" check { @@ -126,8 +132,20 @@ job "dashboard" { } ephemeral_disk { - size = 300 + size = 200 + } + + task "wait-for-db" { + lifecycle { + hook = "prestart" + } + driver = "exec" + config { + command = "sh" + args = ["-c", "while ! nc -z mysql.service.consul 3306 ; do sleep 1 ; done"] + } } + task "grafana" { driver = "exec" logs { @@ -156,11 +174,13 @@ job "dashboard" { data = <