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

     1  # Copyright (c) HashiCorp, Inc.
     2  # SPDX-License-Identifier: MPL-2.0
     3  
     4  job "script_checks_task" {
     5    datacenters = ["dc1"]
     6    type        = "service"
     7  
     8    constraint {
     9      attribute = "${attr.kernel.name}"
    10      value     = "linux"
    11    }
    12  
    13    group "group-a" {
    14  
    15      consul {
    16        namespace = "apple"
    17      }
    18  
    19      task "test" {
    20        service {
    21          name = "service-1a"
    22  
    23          check {
    24            name     = "alive-1"
    25            type     = "script"
    26            interval = "2s"
    27            timeout  = "2s"
    28            command  = "echo"
    29            args     = ["alive-1"]
    30          }
    31        }
    32  
    33        service {
    34          name = "service-2a"
    35  
    36          check {
    37            name     = "alive-2a"
    38            type     = "script"
    39            interval = "2s"
    40            timeout  = "2s"
    41            command  = "echo"
    42            args     = ["alive-2a"]
    43          }
    44  
    45          # the file expected by this check will not exist when started,
    46          # so the check will error-out and be in a warning state until
    47          # it's been created
    48          check {
    49            name     = "alive-2ab"
    50            type     = "script"
    51            interval = "2s"
    52            timeout  = "2s"
    53            command  = "cat"
    54            args     = ["${NOMAD_TASK_DIR}/alive-2ab"]
    55          }
    56        }
    57  
    58        service {
    59          name = "service-3a"
    60  
    61          # this check should always time out and so the service
    62          # should not be marked healthy
    63          check {
    64            name     = "always-dead"
    65            type     = "script"
    66            interval = "2s"
    67            timeout  = "1s"
    68            command  = "sleep"
    69            args     = ["10"]
    70          }
    71        }
    72  
    73        driver = "raw_exec"
    74  
    75        config {
    76          command = "bash"
    77          args    = ["-c", "sleep 15000"]
    78        }
    79      }
    80    }
    81  
    82    group "group-z" {
    83  
    84      # consul namespace not set
    85  
    86      task "test" {
    87        service {
    88          name = "service-1z"
    89  
    90          check {
    91            name     = "alive-1"
    92            type     = "script"
    93            interval = "2s"
    94            timeout  = "2s"
    95            command  = "echo"
    96            args     = ["alive-1z"]
    97          }
    98        }
    99  
   100        service {
   101          name = "service-2z"
   102  
   103          check {
   104            name     = "alive-2z"
   105            type     = "script"
   106            interval = "2s"
   107            timeout  = "2s"
   108            command  = "echo"
   109            args     = ["alive-2z"]
   110          }
   111  
   112          # the file expected by this check will not exist when started,
   113          # so the check will error-out and be in a warning state until
   114          # it's been created
   115          check {
   116            name     = "alive-2zb"
   117            type     = "script"
   118            interval = "2s"
   119            timeout  = "2s"
   120            command  = "cat"
   121            args     = ["${NOMAD_TASK_DIR}/alive-2zb"]
   122          }
   123        }
   124  
   125        service {
   126          name = "service-3z"
   127  
   128          # this check should always time out and so the service
   129          # should not be marked healthy
   130          check {
   131            name     = "always-dead"
   132            type     = "script"
   133            interval = "2s"
   134            timeout  = "1s"
   135            command  = "sleep"
   136            args     = ["10"]
   137          }
   138        }
   139  
   140        driver = "raw_exec"
   141  
   142        config {
   143          command = "bash"
   144          args    = ["-c", "sleep 15000"]
   145        }
   146      }
   147    }
   148  }