2022-07-28 00:02:29 +00:00
|
|
|
job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
|
2022-05-18 21:23:28 +00:00
|
|
|
datacenters = ["dc1"]
|
2022-07-28 00:02:29 +00:00
|
|
|
%{ if batch_node == null ~}
|
2022-06-23 16:49:57 +00:00
|
|
|
type = "system"
|
2022-07-28 00:02:29 +00:00
|
|
|
%{ else ~}
|
|
|
|
type = "batch"
|
2022-05-18 21:23:28 +00:00
|
|
|
|
2022-07-28 00:02:29 +00:00
|
|
|
parameterized {
|
|
|
|
meta_required = ["job_name"]
|
|
|
|
meta_optional = ["task", "snapshot"]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
meta {
|
|
|
|
task = "backup"
|
|
|
|
snapshot = "latest"
|
|
|
|
}
|
|
|
|
%{ endif ~}
|
|
|
|
|
|
|
|
%{ if batch_node == null ~}
|
|
|
|
constraint {
|
|
|
|
attribute = "$${node.unique.name}"
|
|
|
|
operator = "set_contains_any"
|
|
|
|
# Only deploy to nodes running tasks to backup
|
|
|
|
value = "n1,n2"
|
|
|
|
}
|
|
|
|
%{ else ~}
|
2022-06-23 16:49:57 +00:00
|
|
|
constraint {
|
2022-07-28 00:02:29 +00:00
|
|
|
attribute = "$${node.unique.name}"
|
|
|
|
value = "${batch_node}"
|
2022-06-23 16:49:57 +00:00
|
|
|
}
|
2022-07-28 00:02:29 +00:00
|
|
|
%{ endif ~}
|
2022-06-23 16:49:57 +00:00
|
|
|
|
|
|
|
group "backup" {
|
2022-05-18 21:23:28 +00:00
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "metrics" {
|
|
|
|
to = 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 16:49:57 +00:00
|
|
|
volume "all-volumes" {
|
2022-05-18 21:23:28 +00:00
|
|
|
type = "host"
|
2022-07-28 05:04:22 +00:00
|
|
|
read_only = false
|
2022-06-23 16:49:57 +00:00
|
|
|
source = "all-volumes"
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-10-31 22:21:03 +00:00
|
|
|
name = "backups"
|
2022-05-18 21:23:28 +00:00
|
|
|
port = "metrics"
|
|
|
|
|
|
|
|
# Add connect to mysql
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
local_service_port = 8080
|
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 6060
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
protocol = "tcp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meta {
|
2022-07-28 00:02:29 +00:00
|
|
|
metrics_addr = "$${NOMAD_ADDR_metrics}"
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "backup" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
volume_mount {
|
2022-06-23 16:49:57 +00:00
|
|
|
volume = "all-volumes"
|
|
|
|
destination = "/data"
|
2022-07-28 05:04:22 +00:00
|
|
|
read_only = false
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "iamthefij/resticscheduler"
|
|
|
|
ports = ["metrics"]
|
|
|
|
args = [
|
2022-07-28 00:02:29 +00:00
|
|
|
%{ if batch_node != null ~}
|
|
|
|
"-once",
|
|
|
|
"-$${NOMAD_META_task}",
|
|
|
|
"$${NOMAD_META_job_name}",
|
|
|
|
%{ endif ~}
|
2022-11-04 05:17:26 +00:00
|
|
|
"$${NOMAD_TASK_DIR}/node-jobs.hcl",
|
2022-05-18 21:23:28 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-07-22 02:03:40 +00:00
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-05-18 21:23:28 +00:00
|
|
|
env = {
|
2022-07-28 00:02:29 +00:00
|
|
|
"MYSQL_HOST" = "$${NOMAD_UPSTREAM_IP_mysql_server}"
|
|
|
|
"MYSQL_PORT" = "$${NOMAD_UPSTREAM_PORT_mysql_server}"
|
2022-11-04 05:17:48 +00:00
|
|
|
"RCLONE_CHECKERS" = "2"
|
|
|
|
"RCLONE_TRANSFERS" = "2"
|
|
|
|
"RCLONE_FTP_CONCURRENCY" = "5"
|
2022-07-22 02:03:40 +00:00
|
|
|
}
|
2022-05-18 21:23:28 +00:00
|
|
|
|
2022-07-22 02:03:40 +00:00
|
|
|
template {
|
|
|
|
data = <<EOF
|
2022-11-03 03:30:04 +00:00
|
|
|
{{ with secret "kv/data/mysql" }}
|
|
|
|
MYSQL_USER=root
|
|
|
|
MYSQL_PASSWORD={{ .Data.data.root_password }}
|
2022-11-03 22:10:09 +00:00
|
|
|
{{ end -}}
|
2022-07-28 05:04:22 +00:00
|
|
|
{{ with secret "kv/data/backups" -}}
|
2022-07-22 02:03:40 +00:00
|
|
|
BACKUP_PASSPHRASE={{ .Data.data.backup_passphrase }}
|
2022-07-28 05:04:22 +00:00
|
|
|
RCLONE_FTP_HOST={{ .Data.data.nas_ftp_host }}
|
|
|
|
RCLONE_FTP_USER={{ .Data.data.nas_ftp_user }}
|
|
|
|
RCLONE_FTP_PASS={{ .Data.data.nas_ftp_pass | toJSON }}
|
|
|
|
RCLONE_FTP_EXPLICIT_TLS=true
|
|
|
|
RCLONE_FTP_NO_CHECK_CERTIFICATE=true
|
|
|
|
{{ end -}}
|
2022-07-22 02:03:40 +00:00
|
|
|
EOF
|
|
|
|
destination = "secrets/db.env"
|
|
|
|
env = true
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 23:29:06 +00:00
|
|
|
template {
|
|
|
|
data = <<EOH
|
|
|
|
CONSUL_HTTP_ADDR={{ env "attr.unique.network.ip-address" }}:8500
|
|
|
|
EOH
|
|
|
|
destination = "local/consul.env"
|
|
|
|
env = true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-18 21:23:28 +00:00
|
|
|
template {
|
2022-07-22 02:03:40 +00:00
|
|
|
# Build jobs based on node
|
2022-06-23 16:49:57 +00:00
|
|
|
data = <<EOF
|
|
|
|
# Current node is {{ env "node.unique.name" }}
|
2022-07-25 22:50:25 +00:00
|
|
|
{{ if eq (env "node.unique.name") "n2" -}}
|
|
|
|
# Consul backup
|
2022-07-28 00:02:29 +00:00
|
|
|
${file("${module_path}/jobs/consul.hcl")}
|
2022-07-25 22:50:25 +00:00
|
|
|
{{ end -}}
|
2022-10-27 21:28:34 +00:00
|
|
|
|
2022-07-28 00:02:29 +00:00
|
|
|
{{ range service "nextcloud" -}}
|
2022-06-23 16:49:57 +00:00
|
|
|
# Nextcloud .Node {{ .Node }}
|
2022-07-28 00:02:29 +00:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/nextcloud.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
2022-10-27 21:28:34 +00:00
|
|
|
|
2022-11-03 03:30:04 +00:00
|
|
|
{{ range service "grafana" -}}
|
|
|
|
# Grafana .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/grafana.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
|
2022-07-28 00:02:29 +00:00
|
|
|
{{ range service "lldap" -}}
|
|
|
|
# Lldap .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/lldap.hcl")}
|
|
|
|
{{ end -}}
|
2022-10-27 21:28:34 +00:00
|
|
|
{{ end -}}
|
|
|
|
|
|
|
|
{{ range service "sonarr" -}}
|
|
|
|
# Lldap .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/sonarr.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
|
|
|
|
{{ range service "nzbget" -}}
|
|
|
|
# Lldap .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/nzbget.hcl")}
|
|
|
|
{{ end -}}
|
2022-07-28 00:02:29 +00:00
|
|
|
{{ end -}}
|
2022-06-23 16:49:57 +00:00
|
|
|
EOF
|
2022-11-04 05:17:26 +00:00
|
|
|
destination = "local/node-jobs.hcl"
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|