Updating task template without triggering a restart

Hello. Is there a way to update a task’s template without triggering a restart? Rather, I want it to use the new template only if the task restarts, but not while it’s still running since I don’t want to disrupt the operation and cause downtime. The template is mapped to a config for Redis or Postgres. For example

template {
  data = <<-EOF
    save 60 1000
  EOF
  destination = "local/redis.conf"
}

In other words, I’m trying to update a config value but don’t want to trigger a full restart since I can also hot enable the config option (save 60 1000) within Redis while it’s still running. But if it does restart in the future, it should read the new config option within the template. Any suggestions on how I could solve this? Thank you!

Just giving this a lil ole bump

Hi @axsuul. Thanks for using Nomad.

Is this noop setting what you are looking for?

Seems like it, however I’m not sure if noop is maybe not working correctly for me. I tested with this job file on 1.2.5

job "issue-noop" {
  datacenters = ["dc1"]

  group "issue-noop" {
    task "issue-noop" {
      driver = "raw_exec"

      config {
        command = "/bin/bash"
        args = ["${NOMAD_TASK_DIR}/test.sh"]
      }

      template {
        data = <<-EOF
          #!/bin/bash 

          echo "foobar"

          # Keep script running
          tail -f /dev/null
        EOF
        change_mode = "noop"
        destination = "local/test.sh"
      }
    }
  }
}

I can verify it’s running and STDOUT prints out foobar. Now when I update the job file to be

job "issue-noop" {
  datacenters = ["dc1"]

  group "issue-noop" {
    task "issue-noop" {
      driver = "raw_exec"

      config {
        command = "/bin/bash"
        args = ["${NOMAD_TASK_DIR}/test.sh"]
      }

      template {
        data = <<-EOF
          #!/bin/bash 

          echo "baz"

          # Keep script running
          tail -f /dev/null
        EOF
        change_mode = "noop"
        destination = "local/test.sh"
      }
    }
  }
}

with only the template changing, the task automatically restarts even though I have noop and STDOUT now is showing baz even though I’m expecting the task to not have restarted. Am I using this correctly?

The noop will come into effect when you use constructs like {{key ... or {{secret ... which fetch from Consul and Vault.

When you change the contents of the job file itself, the job will get resubmitted (i.e. update).

1 Like