Replace supercronic with minit

This commit is contained in:
Daniel Berteaud 2024-01-19 23:31:41 +01:00
parent 3988173036
commit acbb3e02c3
7 changed files with 68 additions and 75 deletions

View File

@ -1,4 +1,4 @@
FROM danielberteaud/mariadb-client:24.1-1 FROM danielberteaud/mariadb-client:24.1-2
MAINTAINER Daniel Berteaud <dbd@ehtrace.com> MAINTAINER Daniel Berteaud <dbd@ehtrace.com>
RUN set -eux &&\ RUN set -eux &&\

View File

@ -69,7 +69,7 @@ job "mariadb-manage" {
driver = "docker" driver = "docker"
config { config {
image = "danielberteaud/mariadb-client:24.1-1" image = "danielberteaud/mariadb-client:24.1-2"
pids_limit = 50 pids_limit = 50
readonly_rootfs = true readonly_rootfs = true
command = "/local/manage.sh" command = "/local/manage.sh"

View File

@ -1,6 +1,4 @@
job "mariadb" { job "mariadb" {
datacenters = ["dc1"] datacenters = ["dc1"]
@ -10,14 +8,16 @@ job "mariadb" {
mode = "bridge" mode = "bridge"
} }
volume "mariadb" {
type = "csi" volume "data" {
source = "mariadb-data" source = "mariadb-data"
type = "csi"
access_mode = "single-node-writer" access_mode = "single-node-writer"
attachment_mode = "file-system" attachment_mode = "file-system"
per_alloc = true per_alloc = true
} }
service { service {
name = "mariadb" name = "mariadb"
port = 3306 port = 3306
@ -58,17 +58,19 @@ job "mariadb" {
} }
config { config {
image = "danielberteaud/mariadb:24.1-5" image = "danielberteaud/mariadb:24.1-6"
pids_limit = 100 pids_limit = 100
command = "/local/mysql_upgrade.sh" command = "/local/mysql_upgrade.sh"
} }
vault { vault {
policies = ["mariadb"] policies = ["mariadb"]
env = false env = false
disable_file = true disable_file = true
} }
template { template {
data = <<_EOT data = <<_EOT
[client] [client]
@ -109,7 +111,7 @@ _EOT
} }
volume_mount { volume_mount {
volume = "mariadb" volume = "data"
destination = "/data" destination = "/data"
} }
@ -127,7 +129,7 @@ _EOT
kill_timeout = "5m" kill_timeout = "5m"
config { config {
image = "danielberteaud/mariadb:24.1-5" image = "danielberteaud/mariadb:24.1-6"
volumes = [ volumes = [
"secrets/:/etc/my.cnf.d", "secrets/:/etc/my.cnf.d",
"secrets/my.conf:/var/lib/mysql/.my.cnf:ro", "secrets/my.conf:/var/lib/mysql/.my.cnf:ro",
@ -136,12 +138,14 @@ _EOT
#readonly_rootfs = true #readonly_rootfs = true
} }
vault { vault {
policies = ["mariadb"] policies = ["mariadb"]
env = false env = false
disable_file = true disable_file = true
} }
env { env {
MYSQL_CONF_11_bind-address = "127.0.0.1" MYSQL_CONF_11_bind-address = "127.0.0.1"
@ -176,7 +180,7 @@ _EOT
} }
volume_mount { volume_mount {
volume = "mariadb" volume = "data"
destination = "/data" destination = "/data"
} }

View File

@ -1,5 +1,6 @@
[[- $c := merge .mariadb.server . -]] job "[[ .instance ]]" {
job [[ .instance | toJSON ]] {
[[- $c := merge .mariadb.server .mariadb . -]]
[[ template "common/job_start" $c ]] [[ template "common/job_start" $c ]]
@ -9,13 +10,7 @@ job [[ .instance | toJSON ]] {
mode = "bridge" mode = "bridge"
} }
volume "mariadb" { [[ template "common/volumes" $c ]]
type = [[ .mariadb.volumes.data.type | toJSON ]]
source = [[ .mariadb.volumes.data.source | toJSON ]]
access_mode = "single-node-writer"
attachment_mode = "file-system"
per_alloc = true
}
service { service {
name = "[[ .instance ]][[ $c.consul.suffix ]]" name = "[[ .instance ]][[ $c.consul.suffix ]]"
@ -47,23 +42,19 @@ job [[ .instance | toJSON ]] {
# Run mysql_upgrade # Run mysql_upgrade
task "upgrade" { task "upgrade" {
driver = [[ $c.nomad.driver | toJSON ]] driver = "[[ $c.nomad.driver ]]"
lifecycle { lifecycle {
hook = "poststart" hook = "poststart"
} }
config { config {
image = [[ .mariadb.server.image | toJSON ]] image = "[[ .mariadb.server.image ]]"
pids_limit = 100 pids_limit = 100
command = "/local/mysql_upgrade.sh" command = "/local/mysql_upgrade.sh"
} }
vault { [[ template "common/vault.policies" $c ]]
policies = ["[[ .instance ]][[ .consul.suffix ]]"]
env = false
disable_file = true
}
template { template {
data = <<_EOT data = <<_EOT
@ -87,7 +78,7 @@ _EOT
} }
volume_mount { volume_mount {
volume = "mariadb" volume = "data"
destination = "/data" destination = "/data"
} }
@ -99,13 +90,13 @@ _EOT
} }
task "mariadb" { task "mariadb" {
driver = [[ $c.nomad.driver | toJSON ]] driver = "[[ $c.nomad.driver ]]"
leader = true leader = true
kill_timeout = "5m" kill_timeout = "5m"
config { config {
image = [[ .mariadb.server.image | toJSON ]] image = "[[ .mariadb.server.image ]]"
volumes = [ volumes = [
"secrets/:/etc/my.cnf.d", "secrets/:/etc/my.cnf.d",
"secrets/my.conf:/var/lib/mysql/.my.cnf:ro", "secrets/my.conf:/var/lib/mysql/.my.cnf:ro",
@ -114,11 +105,7 @@ _EOT
#readonly_rootfs = true #readonly_rootfs = true
} }
vault { [[ template "common/vault.policies" $c ]]
policies = ["[[ .instance ]][[ .consul.suffix ]]"]
env = false
disable_file = true
}
env { env {
MYSQL_CONF_11_bind-address = "127.0.0.1" MYSQL_CONF_11_bind-address = "127.0.0.1"
@ -151,29 +138,25 @@ _EOT
} }
volume_mount { volume_mount {
volume = "mariadb" volume = "data"
destination = "/data" destination = "/data"
} }
[[ template "common/resources" .mariadb.server.resources ]] [[ template "common/resources" $c ]]
} }
} }
[[- if .mariadb.backup.dumps.enabled ]] [[- if .mariadb.backup.dumps.enabled ]]
[[- $c := merge .mariadb.backup . ]] [[- $c := merge .mariadb.backup .mariadb . ]]
group "backup" { group "backup" {
network { network {
mode = "bridge" mode = "bridge"
} }
volume "backup" { [[ template "common/volumes" $c ]]
type = [[ .mariadb.volumes.backup.type | toJSON ]]
source = [[ .mariadb.volumes.backup.source | toJSON ]]
access_mode = "multi-node-multi-writer"
attachment_mode = "file-system"
}
service { service {
name = "[[ .instance ]]-backup[[ $c.consul.suffix ]]" name = "[[ .instance ]]-backup[[ $c.consul.suffix ]]"
@ -183,22 +166,19 @@ _EOT
[[ template "common/task.wait_for" $c ]] [[ template "common/task.wait_for" $c ]]
task "backup" { task "backup" {
driver = [[ $c.nomad.driver | toJSON ]] driver = "[[ $c.nomad.driver ]]"
config { config {
image = [[ .mariadb.backup.image | toJSON ]] image = "[[ .mariadb.backup.image ]]"
pids_limit = 100 pids_limit = 100
readonly_rootfs = true readonly_rootfs = true
command = "supercronic" command = "minit"
args = [
"/secrets/backup.cron"
]
} }
vault { [[ template "common/vault.policies" $c ]]
policies = ["[[ .instance ]][[ $c.consul.suffix ]]"]
env = false env {
disable_file = true MINIT_UNIT_DIR = "/local/minit.d"
} }
template { template {
@ -224,9 +204,9 @@ _EOT
template { template {
data =<<_EOT data =<<_EOT
[[ template "mariadb/backup.cron.tpl" $c ]] [[ template "mariadb/backup.minit.yml.tpl" $c ]]
_EOT _EOT
destination = "secrets/backup.cron" destination = "local/minit.d/backup.yml"
} }
volume_mount { volume_mount {
@ -234,7 +214,7 @@ _EOT
destination = "/backup" destination = "/backup"
} }
[[ template "common/resources" .mariadb.backup.resources ]] [[ template "common/resources" $c ]]
} }
} }

View File

@ -1,3 +0,0 @@
[[- if and .mariadb.backup.dumps.enabled (not (eq .mariadb.backup.dumps.cron "")) ]]
[[ .mariadb.backup.dumps.cron ]] /local/dump.sh
[[- end ]]

View File

@ -0,0 +1,5 @@
---
kind: cron
name: mariadb-dump
command: ["/local/dump.sh"]
cron: '[[ .mariadb.backup.dumps.cron ]]'

View File

@ -5,6 +5,10 @@ instance: mariadb
mariadb: mariadb:
vault:
policies:
- '[[ .instance ]][[ .consul.suffix ]]'
# MariaDB server settings # MariaDB server settings
server: server:
@ -39,6 +43,16 @@ mariadb:
# We disable the default TCP check, as it adds log noise # We disable the default TCP check, as it adds log noise
disable_default_tcp_check: true disable_default_tcp_check: true
volumes:
# The data volume is opened as single-node-writer
# recommended to be a block based volume (iSCSI for example)
# Also, this volume will connect per alloc, so the alloc ID will be appended.
# You need to create at least mariadb-data[0]
data:
type: csi
source: '[[ .instance ]]-data'
per_alloc: true
# The manager is a batch job which can # The manager is a batch job which can
# - create databases # - create databases
# - create users, and add grants # - create users, and add grants
@ -85,7 +99,7 @@ mariadb:
# Backup service, which can create regular dumps of the databases # Backup service, which can create regular dumps of the databases
backup: backup:
image: '[[ .docker.repo ]]mariadb-backup:24.1-1' image: '[[ .docker.repo ]][[ .docker.base_images.mariadb_client.image ]]'
# Resource allocation # Resource allocation
resources: resources:
@ -110,18 +124,11 @@ mariadb:
compression: 6 compression: 6
cron: 12 03 * * * cron: 12 03 * * *
# Volumes used volumes:
volumes: # Volume which holds database dumps
# The data volume is opened as single-node-writer # will be opened as multi-node-multi-writer (can be NFS for example)
# recommended to be a block based volume (iSCSI for example) backup:
# Also, this volume will connect per alloc, so the alloc ID will be appended. type: csi
# You need to create at least mariadb-data[0] source: '[[ .instance ]]-backup'
data: access_mode: multi-node-multi-writer
type: csi
source: '[[ .instance ]]-data'
# Volume which holds database dumps
# will be opened as multi-node-multi-writer (can be NFS for example)
backup:
type: csi
source: '[[ .instance ]]-backup'