Dear nomad community,
I am learning nomad and wanted to ask about a particular use case and see if this would be a “good” nomad use:
job "enroot-deliver" {
datacenters = ["default"]
type = "service"
group "enroot" {
# Each task should be scheduled on a different node.
constraint {
operator = "distinct_hosts"
value = "true"
}
restart {
mode = "fail"
attempts = 0
}
reschedule {
attempts = "0"
}
task "enroot-deliver" {
lifecycle {
hook = "prestart"
sidecar = false
}
driver = "raw_exec"
user = "root"
config {
command = "bash"
args = ["-c", "zypper install --no-confirm --no-recommends myapp"]
}
}
task "enroot-delivered" {
driver = "exec"
# runs as nobody
config {
command = "sleep"
args = ["inf"]
}
}
task "enroot-remove" {
lifecycle {
hook = "poststop"
sidecar = false
}
driver = "raw_exec"
user = "root"
config {
command = "bash"
args = ["-c", "zypper remove --no-confirm myapp"]
}
}
}
}
The whole point is to use the lifecycle to install/uninstall the application when the job starts/finishes
To me, this would be a very nice use case but on the other hand, I feel this is against Nomad’s original design.
So my question is.
Would this be a valid use case for nomad service jobs?
if not then, how would you recommend doing this use case?
thank you very much