Define restart behavior in your jobs
Nomad will by default attempt to restart a job locally on the node that it is running or scheduled to be running on. These defaults vary by the scheduler type in use for the job: system, service, or batch.
To customize this behavior, the task group can be annotated with configurable
options using the restart
stanza. Nomad will restart the failed
task up to attempts
times within a provided interval
. Operators can also
choose whether to keep attempting restarts on the same node, or to fail the task
so that it can be rescheduled on another node, via the mode
parameter.
Setting mode to fail
in the restart stanza allows rescheduling to occur
potentially moving the task to another node and is best practice.
The following CLI example shows job status and allocation status for a failed
task that is being restarted by Nomad. Allocations are in the pending
state
while restarts are attempted. The Recent Events
section in the CLI shows
ongoing restart attempts.
In the following example, the allocation ce5bf1d1
is restarted by Nomad
approximately every ten seconds, with a small random jitter. It eventually
reaches its limit of three attempts and transitions into a failed
state, after
which it becomes eligible for rescheduling.