Add more conditional checks to Blocky so it is more resiliant

Hopefully this will allow it to deploy if mysql or vault are down
This commit is contained in:
IamTheFij 2023-02-27 11:52:25 -08:00
parent f8555f0900
commit 3a95fb46db
2 changed files with 7 additions and 6 deletions

View File

@ -150,7 +150,7 @@ job "blocky" {
args = [ args = [
"/bin/bash", "/bin/bash",
"-c", "-c",
"/usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql", "/usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql || echo 'SQL Failed'",
] ]
} }
@ -167,16 +167,16 @@ job "blocky" {
host={{ env "NOMAD_UPSTREAM_IP_mysql_server" }} host={{ env "NOMAD_UPSTREAM_IP_mysql_server" }}
port={{ env "NOMAD_UPSTREAM_PORT_mysql_server" }} port={{ env "NOMAD_UPSTREAM_PORT_mysql_server" }}
user=root user=root
{{ with secret "kv/data/mysql" }} {{ with service "vault" -}}{{ with secret "kv/data/mysql" }}
password={{ .Data.data.root_password }} password={{ .Data.data.root_password }}
{{ end }} {{ end -}}{{ end -}}
EOF EOF
destination = "$${NOMAD_SECRETS_DIR}/my.cnf" destination = "$${NOMAD_SECRETS_DIR}/my.cnf"
} }
template { template {
data = <<EOF data = <<EOF
{{ with secret "kv/data/blocky" -}} {{ with service "vault" -}}{{ with secret "kv/data/blocky" -}}
{{ if .Data.data.db_name -}} {{ if .Data.data.db_name -}}
{{ $db_name := .Data.data.db_name }} {{ $db_name := .Data.data.db_name }}
CREATE DATABASE IF NOT EXISTS `{{ $db_name }}`; CREATE DATABASE IF NOT EXISTS `{{ $db_name }}`;
@ -190,7 +190,7 @@ GRANT SELECT ON `{{ $db_name }}`.* to '{{ .Data.data.db_user_ro }}'@'%';
{{ else -}} {{ else -}}
SELECT 'NOOP'; SELECT 'NOOP';
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}{{ end -}}
EOF EOF
destination = "$${NOMAD_SECRETS_DIR}/bootstrap.sql" destination = "$${NOMAD_SECRETS_DIR}/bootstrap.sql"
} }

View File

@ -104,7 +104,8 @@ queryLog:
type: mysql type: mysql
target: {{ .Data.data.db_user }}:{{ .Data.data.db_pass }}@tcp({{ env "NOMAD_UPSTREAM_ADDR_mysql_server" }})/{{ .Data.data.db_name }}?charset=utf8mb4&parseTime=True&loc=Local target: {{ .Data.data.db_user }}:{{ .Data.data.db_pass }}@tcp({{ env "NOMAD_UPSTREAM_ADDR_mysql_server" }})/{{ .Data.data.db_name }}?charset=utf8mb4&parseTime=True&loc=Local
logRetentionDays: 14 logRetentionDays: 14
{{ end -}}{{ end -}}{{ end -}} {{ end -}}
{{ end -}}{{ end -}}
port: 53 port: 53
httpPort: 4000 httpPort: 4000