github.com/hernad/nomad@v1.6.112/e2e/consul/input/checks_group_restart.nomad (about)

     1  # Copyright (c) HashiCorp, Inc.
     2  # SPDX-License-Identifier: MPL-2.0
     3  
     4  job "group_check_restart" {
     5    datacenters = ["dc1"]
     6    type        = "service"
     7  
     8    constraint {
     9      attribute = "${attr.kernel.name}"
    10      value     = "linux"
    11    }
    12  
    13    group "group_check_restart" {
    14      network {
    15        mode = "bridge"
    16      }
    17  
    18      restart {
    19        attempts = 2
    20        delay    = "1s"
    21        interval = "5m"
    22        mode     = "fail"
    23      }
    24  
    25      service {
    26        name = "group-service-1"
    27        port = "9003"
    28  
    29        # this check should always time out and so the service
    30        # should not be marked healthy, resulting in the tasks
    31        # getting restarted
    32        check {
    33          name     = "always-dead"
    34          type     = "script"
    35          task     = "fail"
    36          interval = "2s"
    37          timeout  = "1s"
    38          command  = "sleep"
    39          args     = ["10"]
    40  
    41          check_restart {
    42            limit           = 2
    43            grace           = "5s"
    44            ignore_warnings = false
    45          }
    46        }
    47      }
    48  
    49      task "fail" {
    50        driver = "raw_exec"
    51  
    52        config {
    53          command = "bash"
    54          args    = ["-c", "sleep 15000"]
    55        }
    56      }
    57  
    58      task "ok" {
    59        driver = "raw_exec"
    60  
    61        config {
    62          command = "bash"
    63          args    = ["-c", "sleep 15000"]
    64        }
    65      }
    66    }
    67  }