2016-10-28 00:36:26 +00:00
|
|
|
---
|
2020-02-06 23:45:31 +00:00
|
|
|
layout: docs
|
2023-01-30 14:48:43 +00:00
|
|
|
page_title: restart Block - Job Specification
|
|
|
|
description: The "restart" block configures a group's behavior on task failure.
|
2016-10-28 00:36:26 +00:00
|
|
|
---
|
|
|
|
|
2023-01-30 14:48:43 +00:00
|
|
|
# `restart` Block
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2020-04-13 21:29:43 +00:00
|
|
|
<Placement
|
|
|
|
groups={[
|
|
|
|
['job', 'group', 'restart'],
|
2020-09-30 13:48:40 +00:00
|
|
|
['job', 'group', 'task', 'restart'],
|
2020-04-13 21:29:43 +00:00
|
|
|
]}
|
|
|
|
/>
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2023-01-30 14:48:43 +00:00
|
|
|
The `restart` block configures a task's behavior on task failure. Restarts
|
2018-01-31 16:39:11 +00:00
|
|
|
happen on the client that is running the task.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
group "example" {
|
|
|
|
restart {
|
|
|
|
attempts = 3
|
|
|
|
delay = "30s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-04-13 21:29:43 +00:00
|
|
|
If specified at the group level, the configuration is inherited by all
|
2022-03-14 19:49:08 +00:00
|
|
|
tasks in the group, including any [sidecar tasks][sidecar_task]. If
|
|
|
|
also present on the task, the policy is merged with the restart policy
|
|
|
|
from the encapsulating task group.
|
2020-04-13 21:29:43 +00:00
|
|
|
|
2020-09-30 13:48:40 +00:00
|
|
|
For example, assuming that the task group restart policy is:
|
|
|
|
|
2020-04-13 21:29:43 +00:00
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
interval = "30m"
|
|
|
|
attempts = 2
|
|
|
|
delay = "15s"
|
|
|
|
mode = "fail"
|
|
|
|
}
|
|
|
|
```
|
2020-09-30 13:48:40 +00:00
|
|
|
|
|
|
|
and the individual task restart policy is:
|
|
|
|
|
2020-04-13 21:29:43 +00:00
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
attempts = 5
|
|
|
|
}
|
|
|
|
```
|
2020-09-30 13:48:40 +00:00
|
|
|
|
|
|
|
then the effective restart policy for the task will be:
|
|
|
|
|
2020-04-13 21:29:43 +00:00
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
interval = "30m"
|
|
|
|
attempts = 5
|
|
|
|
delay = "15s"
|
|
|
|
mode = "fail"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-14 19:49:08 +00:00
|
|
|
Because sidecar tasks don't accept a `restart` block, it's recommended
|
|
|
|
that you set the `restart` for jobs with sidecar tasks at the task
|
|
|
|
level, so that the Connect sidecar can inherit the default `restart`.
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
## `restart` Parameters
|
|
|
|
|
|
|
|
- `attempts` `(int: <varies>)` - Specifies the number of restarts allowed in the
|
|
|
|
configured interval. Defaults vary by job type, see below for more
|
|
|
|
information.
|
|
|
|
|
|
|
|
- `delay` `(string: "15s")` - Specifies the duration to wait before restarting a
|
|
|
|
task. This is specified using a label suffix like "30s" or "1h". A random
|
|
|
|
jitter of up to 25% is added to the delay.
|
|
|
|
|
|
|
|
- `interval` `(string: <varies>)` - Specifies the duration which begins when the
|
|
|
|
first task starts and ensures that only `attempts` number of restarts happens
|
|
|
|
within it. If more than `attempts` number of failures happen, behavior is
|
|
|
|
controlled by `mode`. This is specified using a label suffix like "30s" or
|
|
|
|
"1h". Defaults vary by job type, see below for more information.
|
|
|
|
|
2018-06-14 17:53:50 +00:00
|
|
|
- `mode` `(string: "fail")` - Controls the behavior when the task fails more
|
2016-10-28 03:01:11 +00:00
|
|
|
than `attempts` times in an interval. For a detailed explanation of these
|
|
|
|
values and their behavior, please see the [mode values section](#mode-values).
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
### `restart` Parameter Defaults
|
|
|
|
|
|
|
|
The values for many of the `restart` parameters vary by job type. Here are the
|
|
|
|
defaults by job type:
|
|
|
|
|
|
|
|
- The default batch restart policy is:
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
attempts = 3
|
|
|
|
delay = "15s"
|
|
|
|
interval = "24h"
|
|
|
|
mode = "fail"
|
|
|
|
}
|
|
|
|
```
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2019-05-06 21:52:44 +00:00
|
|
|
- The default service and system job restart policy is:
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
interval = "30m"
|
|
|
|
attempts = 2
|
|
|
|
delay = "15s"
|
|
|
|
mode = "fail"
|
|
|
|
}
|
|
|
|
```
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
### `mode` Values
|
|
|
|
|
|
|
|
This section details the specific values for the "mode" parameter in the Nomad
|
2020-12-01 06:46:24 +00:00
|
|
|
job specification for constraints. The mode is always specified as a string:
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
mode = "..."
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-14 19:49:08 +00:00
|
|
|
- `"delay"` - Instructs the client to wait until another `interval`
|
|
|
|
before restarting the task.
|
|
|
|
|
|
|
|
- `"fail"` - Instructs the client not to attempt to restart the task
|
|
|
|
once the number of `attempts` have been used. This is the default
|
|
|
|
behavior. This mode is useful for non-idempotent jobs which are
|
|
|
|
unlikely to succeed after a few failures. The allocation will be
|
|
|
|
marked as failed and the scheduler will attempt to reschedule the
|
|
|
|
allocation according to the
|
2023-01-30 14:48:43 +00:00
|
|
|
[`reschedule`] block.
|
2022-03-14 19:49:08 +00:00
|
|
|
|
|
|
|
### `restart` Examples
|
|
|
|
|
|
|
|
With the following `restart` block, a failing task will restart 3
|
|
|
|
times with 15 seconds between attempts, and then wait 10 minutes
|
|
|
|
before attempting another 3 attempts. The task restart will never fail
|
|
|
|
the entire allocation.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
attempts = 3
|
|
|
|
delay = "15s"
|
|
|
|
interval = "10m"
|
|
|
|
mode = "delay"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-08-05 20:45:30 +00:00
|
|
|
With the following `restart` block, a task that fails after 1
|
2022-03-14 19:49:08 +00:00
|
|
|
minute, after 2 minutes, and after 3 minutes will be restarted each
|
|
|
|
time. If it fails again before 10 minutes, the entire allocation will
|
|
|
|
be marked as failed and the scheduler will follow the group's
|
|
|
|
[`reschedule`] specification, possibly resulting in a new evaluation.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
restart {
|
|
|
|
attempts = 3
|
|
|
|
delay = "15s"
|
|
|
|
interval = "10m"
|
|
|
|
mode = "fail"
|
|
|
|
}
|
|
|
|
```
|
2016-10-28 00:36:26 +00:00
|
|
|
|
2023-01-25 17:31:14 +00:00
|
|
|
[sidecar_task]: /nomad/docs/job-specification/sidecar_task
|
|
|
|
[`reschedule`]: /nomad/docs/job-specification/reschedule
|