github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/e2eutil/input/restart-node.nomad (about) 1 variable "nodeID" { 2 type = string 3 } 4 5 variable "time" { 6 type = string 7 default = "0" 8 } 9 10 job "restart-node" { 11 type = "batch" 12 datacenters = ["dc1", "dc2"] 13 14 group "group" { 15 16 reschedule { 17 attempts = 0 18 unlimited = false 19 } 20 21 # need to prevent the task from being restarted on reconnect, if 22 # we're stopped long enough for the node to be marked down 23 max_client_disconnect = "1h" 24 25 constraint { 26 attribute = "${attr.kernel.name}" 27 value = "linux" 28 } 29 constraint { 30 attribute = "${node.unique.id}" 31 value = "${var.nodeID}" 32 } 33 34 task "task" { 35 driver = "raw_exec" 36 config { 37 command = "/bin/sh" 38 args = ["-c", 39 # before disconnecting, we need to sleep long enough for the 40 # task to register itself, otherwise we end up trying to 41 # re-run the task immediately on reconnect 42 "sleep 5; systemctl stop nomad; sleep ${var.time}; systemctl start nomad"] 43 } 44 } 45 46 } 47 }