add members-mysql (#46)
This commit is contained in:
parent
3c1b2894a0
commit
804fc4c5e5
2 changed files with 128 additions and 0 deletions
50
jobs/services/members-mysql-backup.hcl
Normal file
50
jobs/services/members-mysql-backup.hcl
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
job "members-mysql-backup" {
|
||||||
|
datacenters = ["aperture"]
|
||||||
|
type = "batch"
|
||||||
|
|
||||||
|
periodic {
|
||||||
|
crons = ["0 */3 * * * *"]
|
||||||
|
prohibit_overlap = true
|
||||||
|
}
|
||||||
|
|
||||||
|
group "db-backup" {
|
||||||
|
task "mysql-backup" {
|
||||||
|
driver = "raw_exec"
|
||||||
|
|
||||||
|
config {
|
||||||
|
command = "/bin/bash"
|
||||||
|
args = ["local/script.sh"]
|
||||||
|
}
|
||||||
|
|
||||||
|
template {
|
||||||
|
data = <<EOH
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
file=/storage/backups/nomad/mysql/members/members-mysql-$(date +%Y-%m-%d_%H-%M-%S).sql
|
||||||
|
|
||||||
|
mkdir -p /storage/backups/nomad/mysql/members
|
||||||
|
|
||||||
|
alloc_id=$(nomad job status members-mysql | grep running | tail -n 1 | cut -d " " -f 1)
|
||||||
|
|
||||||
|
job_name=$(echo ${NOMAD_JOB_NAME} | cut -d "/" -f 1)
|
||||||
|
|
||||||
|
nomad alloc exec $alloc_id mariadb-dump -u root -p'{{ key "members-mysql/root/password"}}' --all-databases > "${file}"
|
||||||
|
|
||||||
|
find /storage/backups/nomad/mysql/members/members-mysql* -ctime +3 -exec rm {} \; || true
|
||||||
|
|
||||||
|
if [ -s "$file" ]; then # check if file exists and is not empty
|
||||||
|
echo "Backup successful"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
rm $file
|
||||||
|
curl -H "Content-Type: application/json" -d \
|
||||||
|
'{"content": "<@&585512338728419341> `MySQL` backup for **'"${job_name}"'** has just **FAILED**\nFile name: `'"$file"'`\nDate: `'"$(TZ=Europe/Dublin date)"'`\nTurn off this script with `nomad job stop '"${job_name}"'` \n\n## Remember to restart this backup job when fixed!!!"}' \
|
||||||
|
{{ key "mysql/webhook/discord" }}
|
||||||
|
fi
|
||||||
|
EOH
|
||||||
|
destination = "local/script.sh"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
78
jobs/services/members-mysql.hcl
Normal file
78
jobs/services/members-mysql.hcl
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
job "members-mysql" {
|
||||||
|
datacenters = ["aperture"]
|
||||||
|
|
||||||
|
constraint {
|
||||||
|
attribute = "${attr.unique.hostname}"
|
||||||
|
value = "wheatley"
|
||||||
|
}
|
||||||
|
|
||||||
|
group "db" {
|
||||||
|
network {
|
||||||
|
port "db" {
|
||||||
|
static = 3306
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task "mariadb" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
template {
|
||||||
|
data = <<EOH
|
||||||
|
MYSQL_ROOT_PASSWORD="{{ key "members-mysql/root/password" }}"
|
||||||
|
MYSQL_USER="{{ key "members-mysql/user/username" }}"
|
||||||
|
MYSQL_PASSWORD="{{ key "members-mysql/user/password" }}"
|
||||||
|
EOH
|
||||||
|
|
||||||
|
destination = "local/file.env"
|
||||||
|
env = true
|
||||||
|
}
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "mariadb:latest"
|
||||||
|
ports = ["db"]
|
||||||
|
|
||||||
|
volumes = [
|
||||||
|
"/opt/members-mysql:/var/lib/mysql",
|
||||||
|
"local/server.cnf:/etc/mysql/mariadb.conf.d/50-server.cnf",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
template {
|
||||||
|
data = <<EOH
|
||||||
|
[server]
|
||||||
|
|
||||||
|
[mariadbd]
|
||||||
|
|
||||||
|
pid-file = /run/mysqld/mysqld.pid
|
||||||
|
basedir = /usr
|
||||||
|
|
||||||
|
bind-address = 0.0.0.0
|
||||||
|
|
||||||
|
expire_logs_days = 10
|
||||||
|
|
||||||
|
character-set-server = utf8mb4
|
||||||
|
character-set-collations = utf8mb4=uca1400_ai_ci
|
||||||
|
|
||||||
|
[mariadbd]
|
||||||
|
EOH
|
||||||
|
destination = "local/server.cnf"
|
||||||
|
}
|
||||||
|
|
||||||
|
resources {
|
||||||
|
cpu = 400
|
||||||
|
memory = 800
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "members-mysql"
|
||||||
|
port = "db"
|
||||||
|
|
||||||
|
check {
|
||||||
|
type = "tcp"
|
||||||
|
interval = "2s"
|
||||||
|
timeout = "2s"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue