Proposal
https://developer.hashicorp.com/nomad/docs/job-specification/change_script
I'd like to propose idea of adding additional option to change_script block in template: run_first or force (or something in the lines of). Main goal of this option would be to give ability to force run script once on task start even if there are no changes in the template. Main reasoning would be in most cases same script would also need to be run anyway (ie bootstrap script, etc).
Use-cases
Any type of reactive autoconfig script based on Nomad variables. For example:
template {
change_mode = "script"
change_script {
command = "bash"
args = ["/local/autoconfig_grafana.sh"]
fail_on_error = true
run_first = true #HERE WE FORCE TO RUN THIS SCRIPT FIRST AFTER TASK START
timeout = "30s"
}
data = <<-EOF
{{- with nomadVar "params/grafana/secrets" }}
GRAFANA_USER="{{ index . "grafana.admin_user" }}"
GRAFANA_PASSWORD="{{ index . "grafana.admin_password" }}"
{{- end }}
EOF
destination = "secrets/env"
env = true
}
Attempted Solutions
Currently I use sidecars, but the script has to keep hanging with infinite wait ie:
task "grafana-autoconfig" {
config {
args = [
"/local/autoconfig_grafana.sh"
]
command = "bash"
...
}
driver = "docker"
kill_timeout = "30s"
lifecycle {
hook = "poststart"
sidecar = true
}
template {
data = <<-EOF
{{- with nomadVar "params/grafana/secrets" }}
GRAFANA_USER="{{ index . "grafana.admin_user" }}"
GRAFANA_PASSWORD="{{ index . "grafana.admin_password" }}"
{{- end }}
EOF
destination = "secrets/env"
env = true
}
...
}
Not ideal as I have to keep resources allocated. And if the task (script) stops immediatelly after it's done it's thing then Nomad no longer restarts task on template changes.
Proposal
https://developer.hashicorp.com/nomad/docs/job-specification/change_script
I'd like to propose idea of adding additional option to
change_scriptblock in template:run_firstorforce(or something in the lines of). Main goal of this option would be to give ability to force run script once on task start even if there are no changes in the template. Main reasoning would be in most cases same script would also need to be run anyway (ie bootstrap script, etc).Use-cases
Any type of reactive autoconfig script based on Nomad variables. For example:
Attempted Solutions
Currently I use sidecars, but the script has to keep hanging with infinite wait ie:
Not ideal as I have to keep resources allocated. And if the task (script) stops immediatelly after it's done it's thing then Nomad no longer restarts task on template changes.