2022-07-27 17:02:29 -07:00
|
|
|
job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" {
|
2022-05-18 14:23:28 -07:00
|
|
|
datacenters = ["dc1"]
|
2022-11-18 08:58:38 -08:00
|
|
|
priority = 90
|
2022-07-27 17:02:29 -07:00
|
|
|
%{ if batch_node == null ~}
|
2022-06-23 09:49:57 -07:00
|
|
|
type = "system"
|
2022-07-27 17:02:29 -07:00
|
|
|
%{ else ~}
|
|
|
|
type = "batch"
|
2022-05-18 14:23:28 -07:00
|
|
|
|
2022-07-27 17:02:29 -07: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 09:49:57 -07:00
|
|
|
constraint {
|
2022-07-27 17:02:29 -07:00
|
|
|
attribute = "$${node.unique.name}"
|
|
|
|
value = "${batch_node}"
|
2022-06-23 09:49:57 -07:00
|
|
|
}
|
2022-07-27 17:02:29 -07:00
|
|
|
%{ endif ~}
|
2022-06-23 09:49:57 -07:00
|
|
|
|
|
|
|
group "backup" {
|
2022-05-18 14:23:28 -07:00
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "metrics" {
|
|
|
|
to = 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 09:49:57 -07:00
|
|
|
volume "all-volumes" {
|
2022-05-18 14:23:28 -07:00
|
|
|
type = "host"
|
2022-07-27 22:04:22 -07:00
|
|
|
read_only = false
|
2022-06-23 09:49:57 -07:00
|
|
|
source = "all-volumes"
|
2022-05-18 14:23:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
2022-10-31 15:21:03 -07:00
|
|
|
name = "backups"
|
2022-05-18 14:23:28 -07:00
|
|
|
port = "metrics"
|
|
|
|
|
|
|
|
# Add connect to mysql
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
local_service_port = 8080
|
|
|
|
|
2022-11-11 13:37:09 -08:00
|
|
|
# TODO: Do I need this?
|
|
|
|
expose {
|
|
|
|
path {
|
|
|
|
path = "/metrics"
|
|
|
|
protocol = "http"
|
|
|
|
local_path_port = 8080
|
|
|
|
listener_port = "metrics"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 14:23:28 -07:00
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 6060
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
protocol = "tcp"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 20:50:18 -08:00
|
|
|
check {
|
|
|
|
port = "metrics"
|
|
|
|
type = "http"
|
|
|
|
path = "/health"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "3s"
|
|
|
|
}
|
|
|
|
|
2022-05-18 14:23:28 -07:00
|
|
|
meta {
|
2022-07-27 17:02:29 -07:00
|
|
|
metrics_addr = "$${NOMAD_ADDR_metrics}"
|
2022-05-18 14:23:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "backup" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
volume_mount {
|
2022-06-23 09:49:57 -07:00
|
|
|
volume = "all-volumes"
|
|
|
|
destination = "/data"
|
2022-07-27 22:04:22 -07:00
|
|
|
read_only = false
|
2022-05-18 14:23:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "iamthefij/resticscheduler"
|
|
|
|
ports = ["metrics"]
|
|
|
|
args = [
|
2022-07-27 17:02:29 -07:00
|
|
|
%{ if batch_node != null ~}
|
|
|
|
"-once",
|
|
|
|
"-$${NOMAD_META_task}",
|
|
|
|
"$${NOMAD_META_job_name}",
|
|
|
|
%{ endif ~}
|
2022-11-03 22:17:26 -07:00
|
|
|
"$${NOMAD_TASK_DIR}/node-jobs.hcl",
|
2022-05-18 14:23:28 -07:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:03:40 -07:00
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-05-18 14:23:28 -07:00
|
|
|
env = {
|
2022-07-27 17:02:29 -07:00
|
|
|
"MYSQL_HOST" = "$${NOMAD_UPSTREAM_IP_mysql_server}"
|
|
|
|
"MYSQL_PORT" = "$${NOMAD_UPSTREAM_PORT_mysql_server}"
|
2022-11-03 22:17:48 -07:00
|
|
|
"RCLONE_CHECKERS" = "2"
|
|
|
|
"RCLONE_TRANSFERS" = "2"
|
|
|
|
"RCLONE_FTP_CONCURRENCY" = "5"
|
2022-07-21 19:03:40 -07:00
|
|
|
}
|
2022-05-18 14:23:28 -07:00
|
|
|
|
2022-07-21 19:03:40 -07:00
|
|
|
template {
|
|
|
|
data = <<EOF
|
2022-11-02 20:30:04 -07:00
|
|
|
{{ with secret "kv/data/mysql" }}
|
|
|
|
MYSQL_USER=root
|
|
|
|
MYSQL_PASSWORD={{ .Data.data.root_password }}
|
2022-11-03 15:10:09 -07:00
|
|
|
{{ end -}}
|
2022-07-27 22:04:22 -07:00
|
|
|
{{ with secret "kv/data/backups" -}}
|
2022-07-21 19:03:40 -07:00
|
|
|
BACKUP_PASSPHRASE={{ .Data.data.backup_passphrase }}
|
2022-07-27 22:04:22 -07: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-21 19:03:40 -07:00
|
|
|
EOF
|
|
|
|
destination = "secrets/db.env"
|
|
|
|
env = true
|
2022-05-18 14:23:28 -07:00
|
|
|
}
|
|
|
|
|
2022-07-25 16:29:06 -07:00
|
|
|
template {
|
|
|
|
data = <<EOH
|
|
|
|
CONSUL_HTTP_ADDR={{ env "attr.unique.network.ip-address" }}:8500
|
|
|
|
EOH
|
|
|
|
destination = "local/consul.env"
|
|
|
|
env = true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-18 14:23:28 -07:00
|
|
|
template {
|
2022-07-21 19:03:40 -07:00
|
|
|
# Build jobs based on node
|
2022-06-23 09:49:57 -07:00
|
|
|
data = <<EOF
|
|
|
|
# Current node is {{ env "node.unique.name" }}
|
2022-07-25 15:50:25 -07:00
|
|
|
{{ if eq (env "node.unique.name") "n2" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# consul backup
|
2022-07-27 17:02:29 -07:00
|
|
|
${file("${module_path}/jobs/consul.hcl")}
|
2022-07-25 15:50:25 -07:00
|
|
|
{{ end -}}
|
2022-10-27 14:28:34 -07:00
|
|
|
|
2022-07-27 17:02:29 -07:00
|
|
|
{{ range service "nextcloud" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# nextcloud .Node {{ .Node }}
|
2022-07-27 17:02:29 -07:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/nextcloud.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
2022-10-27 14:28:34 -07:00
|
|
|
|
2022-11-02 20:30:04 -07:00
|
|
|
{{ range service "grafana" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# grafana .Node {{ .Node }}
|
2022-11-02 20:30:04 -07:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/grafana.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
|
2022-11-15 09:19:55 -08:00
|
|
|
{{ range service "photoprism" -}}
|
|
|
|
# photoprism .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/photoprism.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
|
2022-07-27 17:02:29 -07:00
|
|
|
{{ range service "lldap" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# lldap .Node {{ .Node }}
|
2022-07-27 17:02:29 -07:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/lldap.hcl")}
|
|
|
|
{{ end -}}
|
2022-10-27 14:28:34 -07:00
|
|
|
{{ end -}}
|
|
|
|
|
|
|
|
{{ range service "sonarr" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# sonarr .Node {{ .Node }}
|
2022-10-27 14:28:34 -07:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/sonarr.hcl")}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
|
|
|
|
{{ range service "nzbget" -}}
|
2022-11-04 09:39:08 -07:00
|
|
|
# nzbget .Node {{ .Node }}
|
2022-10-27 14:28:34 -07:00
|
|
|
{{ if eq .Node (env "node.unique.name") -}}
|
|
|
|
${file("${module_path}/jobs/nzbget.hcl")}
|
|
|
|
{{ end -}}
|
2022-07-27 17:02:29 -07:00
|
|
|
{{ end -}}
|
2022-06-23 09:49:57 -07:00
|
|
|
EOF
|
2022-11-03 22:17:26 -07:00
|
|
|
destination = "local/node-jobs.hcl"
|
2022-05-18 14:23:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|