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-11-18 16:58:38 +00:00
|
|
|
priority = 90
|
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 {
|
2023-03-24 23:32:37 +00:00
|
|
|
name = "backup"
|
2023-03-24 18:24:36 +00:00
|
|
|
provider = "nomad"
|
2022-05-18 21:23:28 +00:00
|
|
|
port = "metrics"
|
|
|
|
|
2023-03-24 18:24:36 +00:00
|
|
|
tags = [
|
|
|
|
"prometheus.scrape"
|
|
|
|
]
|
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
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
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
|
2023-03-24 18:24:36 +00:00
|
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "mysql-server" -}}
|
|
|
|
MYSQL_HOST={{ .Address }}
|
|
|
|
MYSQL_PORT={{ .Port }}
|
|
|
|
{{- end }}
|
|
|
|
# TODO: Move this to new mysql root pass path
|
|
|
|
{{ with nomadVar "nomad/jobs" }}
|
2022-11-03 03:30:04 +00:00
|
|
|
MYSQL_USER=root
|
2023-03-24 18:24:36 +00:00
|
|
|
MYSQL_PASSWORD={{ .mysql_root_password }}
|
2022-11-03 22:10:09 +00:00
|
|
|
{{ end -}}
|
2023-03-24 23:32:37 +00:00
|
|
|
{{ with nomadVar "nomad/jobs/backup" -}}
|
2023-03-24 18:24:36 +00:00
|
|
|
BACKUP_PASSPHRASE={{ .backup_passphrase }}
|
|
|
|
RCLONE_FTP_HOST={{ .nas_ftp_host }}
|
|
|
|
RCLONE_FTP_USER={{ .nas_ftp_user }}
|
|
|
|
RCLONE_FTP_PASS={{ .nas_ftp_pass.Value | toJSON }}
|
2022-07-28 05:04:22 +00:00
|
|
|
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
|
|
|
|
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
|
2023-03-25 06:34:23 +00:00
|
|
|
# Current node is {{ env "node.unique.name" }} {{ env "node.unique.id" }}
|
2022-10-27 21:28:34 +00:00
|
|
|
|
2023-03-25 05:58:44 +00:00
|
|
|
{{ range nomadService "grafana" -}}
|
2023-03-25 06:34:23 +00:00
|
|
|
# grafana .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.id") -}}
|
2022-11-03 03:30:04 +00:00
|
|
|
${file("${module_path}/jobs/grafana.hcl")}
|
2023-03-25 05:58:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2022-11-03 03:30:04 +00:00
|
|
|
|
2023-03-25 05:58:44 +00:00
|
|
|
{{ range nomadService "photoprism" -}}
|
2023-03-25 06:34:23 +00:00
|
|
|
# photoprism .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.id") -}}
|
2022-11-15 17:19:55 +00:00
|
|
|
${file("${module_path}/jobs/photoprism.hcl")}
|
2023-03-25 05:58:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2022-11-15 17:19:55 +00:00
|
|
|
|
2023-03-25 06:34:23 +00:00
|
|
|
{{ range nomadService "lldap" -}}
|
|
|
|
# lldap .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.id") -}}
|
2022-07-28 00:02:29 +00:00
|
|
|
${file("${module_path}/jobs/lldap.hcl")}
|
2023-03-25 05:58:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2022-10-27 21:28:34 +00:00
|
|
|
|
2023-03-25 06:34:23 +00:00
|
|
|
{{ range nomadService "sonarr" -}}
|
|
|
|
# sonarr .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.id") -}}
|
2022-10-27 21:28:34 +00:00
|
|
|
${file("${module_path}/jobs/sonarr.hcl")}
|
2023-03-25 05:58:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2022-10-27 21:28:34 +00:00
|
|
|
|
2023-03-25 06:34:23 +00:00
|
|
|
{{ range nomadService "nzbget" -}}
|
|
|
|
# nzbget .Node {{ .Node }}
|
|
|
|
{{ if eq .Node (env "node.unique.id") -}}
|
2022-10-27 21:28:34 +00:00
|
|
|
${file("${module_path}/jobs/nzbget.hcl")}
|
2023-03-25 05:58:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|