The information contained in this article has been verified as up-to-date on the date of the original publication of the article. HashiCorp endeavors to keep this information up-to-date and correct, but it makes no representations or warranties of any kind, express or implied, about the ongoing completeness, accuracy, reliability, or suitability of the information provided.
All information contained in this article is for general information purposes only. Any reliance you place on such information as it applies to your use of your HashiCorp product is therefore strictly at your own risk.
In Nomad, whenever a task within a job fails or stops, Nomad will automatically try to start the task by either restarting the existing allocation or rescheduling an new allocation on another node. This default behavior is controlled by the restart and reschedule policy in the job definition. For example, Nomad client will typically attempt to restart a failed task twice by default.
restart {
attempts = 2
delay = "15s"
interval = "30m"
mode = "fail"
}
However, there are situations where you might not want a task to restart once it stops, possibly because it has completed its intended purpose. In such cases, you might prefer to keep the task in a failed state without fully removing it from the allocation status. This way, the task remains visible for review or audit purposes, but it doesn't kick back into action automatically.
To make sure a task doesn't restart after it stops, you need to configure the settings in your job's configuration. This involves adjusting both the restart and reschedule blocks in your job definition. Here's how you can do it, and you can apply these settings either to an individual task level or to an entire group level.
restart {
attempts = 0
mode = "fail"
}
reschedule {
attempts = 0
unlimited = false
}
The restart block is your first step, which instructs the Nomad client not to restart the existing allocation if it stops. However, by itself, this might not be enough because Nomad could still try to schedule a new allocation for the task. That's where the reschedule block comes in. By setting it up as shown, you're telling Nomad not to bother creating a new allocation for the task. Together, these settings ensure that once your task fails or stops, it stays stopped.
Reference:
- Restart configuration
- Reschedule configuration