github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/restart.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: restart Stanza - Job Specification
     4  sidebar_title: restart
     5  description: The "restart" stanza configures a group's behavior on task failure.
     6  ---
     7  
     8  # `restart` Stanza
     9  
    10  <Placement
    11    groups={[
    12      ['job', 'group', 'restart'],
    13      ['job', 'group', 'task', 'restart'],
    14    ]}
    15  />
    16  
    17  The `restart` stanza configures a tasks's behavior on task failure. Restarts
    18  happen on the client that is running the task.
    19  
    20  ```hcl
    21  job "docs" {
    22    group "example" {
    23      restart {
    24        attempts = 3
    25        delay    = "30s"
    26      }
    27    }
    28  }
    29  ```
    30  
    31  If specified at the group level, the configuration is inherited by all
    32  tasks in the group. If present on the task, the policy is merged with
    33  the restart policy from the encapsulating task group.
    34  
    35  For example, assuming that the task group restart policy is:
    36  
    37  ```hcl
    38  restart {
    39    interval = "30m"
    40    attempts = 2
    41    delay    = "15s"
    42    mode     = "fail"
    43  }
    44  ```
    45  
    46  and the individual task restart policy is:
    47  
    48  ```hcl
    49  restart {
    50    attempts = 5
    51  }
    52  ```
    53  
    54  then the effective restart policy for the task will be:
    55  
    56  ```hcl
    57  restart {
    58    interval = "30m"
    59    attempts = 5
    60    delay    = "15s"
    61    mode     = "fail"
    62  }
    63  ```
    64  
    65  ## `restart` Parameters
    66  
    67  - `attempts` `(int: <varies>)` - Specifies the number of restarts allowed in the
    68    configured interval. Defaults vary by job type, see below for more
    69    information.
    70  
    71  - `delay` `(string: "15s")` - Specifies the duration to wait before restarting a
    72    task. This is specified using a label suffix like "30s" or "1h". A random
    73    jitter of up to 25% is added to the delay.
    74  
    75  - `interval` `(string: <varies>)` - Specifies the duration which begins when the
    76    first task starts and ensures that only `attempts` number of restarts happens
    77    within it. If more than `attempts` number of failures happen, behavior is
    78    controlled by `mode`. This is specified using a label suffix like "30s" or
    79    "1h". Defaults vary by job type, see below for more information.
    80  
    81  - `mode` `(string: "fail")` - Controls the behavior when the task fails more
    82    than `attempts` times in an interval. For a detailed explanation of these
    83    values and their behavior, please see the [mode values section](#mode-values).
    84  
    85  ### `restart` Parameter Defaults
    86  
    87  The values for many of the `restart` parameters vary by job type. Here are the
    88  defaults by job type:
    89  
    90  - The default batch restart policy is:
    91  
    92    ```hcl
    93    restart {
    94      attempts = 3
    95      delay    = "15s"
    96      interval = "24h"
    97      mode     = "fail"
    98    }
    99    ```
   100  
   101  - The default service and system job restart policy is:
   102  
   103    ```hcl
   104    restart {
   105      interval = "30m"
   106      attempts = 2
   107      delay    = "15s"
   108      mode     = "fail"
   109    }
   110    ```
   111  
   112  ### `mode` Values
   113  
   114  This section details the specific values for the "mode" parameter in the Nomad
   115  job specification for constraints. The mode is always specified as a string:
   116  
   117  ```hcl
   118  restart {
   119    mode = "..."
   120  }
   121  ```
   122  
   123  - `"delay"` - Instructs the scheduler to delay the next restart until the next
   124    `interval` is reached.
   125  
   126  - `"fail"` - Instructs the scheduler to not attempt to restart the task on
   127    failure. This is the default behavior. This mode is useful for non-idempotent jobs which are unlikely to
   128    succeed after a few failures. Failed jobs will be restarted according to
   129    the [`reschedule`](/docs/job-specification/reschedule) stanza.