github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/lifecycle/inputs/batch.nomad (about)

     1  # lifecycle hook test job for batch jobs. touches, removes, and tests
     2  # for the existence of files to assert the order of running tasks.
     3  # all tasks should exit 0 and the alloc dir should contain the following
     4  # files: ./init-ran, ./main-ran, ./poststart-run
     5  
     6  job "batch-lifecycle" {
     7  
     8    datacenters = ["dc1"]
     9  
    10    type = "batch"
    11  
    12    constraint {
    13      attribute = "${attr.kernel.name}"
    14      value     = "linux"
    15    }
    16  
    17    group "test" {
    18  
    19      task "init" {
    20  
    21        lifecycle {
    22          hook = "prestart"
    23        }
    24  
    25        driver = "docker"
    26  
    27        config {
    28          image   = "busybox:1"
    29          command = "/bin/sh"
    30          args    = ["local/prestart.sh"]
    31        }
    32  
    33        template {
    34          data = <<EOT
    35  #!/bin/sh
    36  sleep 1
    37  touch ${NOMAD_ALLOC_DIR}/init-ran
    38  touch ${NOMAD_ALLOC_DIR}/init-running
    39  sleep 5
    40  if [ -f ${NOMAD_ALLOC_DIR}/main ]; then exit 7; fi
    41  if [ -f ${NOMAD_ALLOC_DIR}/poststart-running ]; then exit 8; fi
    42  rm ${NOMAD_ALLOC_DIR}/init-running
    43  EOT
    44  
    45          destination = "local/prestart.sh"
    46  
    47        }
    48  
    49        resources {
    50          cpu    = 64
    51          memory = 64
    52        }
    53      }
    54  
    55      task "main" {
    56  
    57        driver = "docker"
    58  
    59        config {
    60          image   = "busybox:1"
    61          command = "/bin/sh"
    62          args    = ["local/main.sh"]
    63        }
    64  
    65        template {
    66          data = <<EOT
    67  #!/bin/sh
    68  sleep 1
    69  touch ${NOMAD_ALLOC_DIR}/main-running
    70  touch ${NOMAD_ALLOC_DIR}/main-started
    71  # NEED TO HANG AROUND TO GIVE POSTSTART TIME TO GET STARTED
    72  sleep 10
    73  if [ ! -f ${NOMAD_ALLOC_DIR}/init-ran ]; then exit 9; fi
    74  if [ -f ${NOMAD_ALLOC_DIR}/init-running ]; then exit 10; fi
    75  
    76  if [ ! -f ${NOMAD_ALLOC_DIR}/poststart-started ]; then exit 11; fi
    77  
    78  touch ${NOMAD_ALLOC_DIR}/main-ran
    79  rm ${NOMAD_ALLOC_DIR}/main-running
    80  EOT
    81  
    82          destination = "local/main.sh"
    83        }
    84  
    85        resources {
    86          cpu    = 64
    87          memory = 64
    88        }
    89      }
    90  
    91  
    92      task "poststart" {
    93  
    94        lifecycle {
    95          hook = "poststart"
    96        }
    97  
    98        driver = "docker"
    99  
   100        config {
   101          image   = "busybox:1"
   102          command = "/bin/sh"
   103          args    = ["local/poststart.sh"]
   104        }
   105  
   106        template {
   107          data = <<EOT
   108  #!/bin/sh
   109  sleep 1
   110  touch ${NOMAD_ALLOC_DIR}/poststart-ran
   111  touch ${NOMAD_ALLOC_DIR}/poststart-running
   112  touch ${NOMAD_ALLOC_DIR}/poststart-started
   113  sleep 10
   114  
   115  if [ ! -f ${NOMAD_ALLOC_DIR}/init-ran ]; then exit 12; fi
   116  if [ ! -f ${NOMAD_ALLOC_DIR}/main-started ]; then exit 15; fi
   117  if [ -f ${NOMAD_ALLOC_DIR}/init-running ]; then exit 14; fi
   118  rm ${NOMAD_ALLOC_DIR}/poststart-running
   119  EOT
   120  
   121          destination = "local/poststart.sh"
   122        }
   123  
   124        resources {
   125          cpu    = 64
   126          memory = 64
   127        }
   128      }
   129  
   130      task "poststop" {
   131  
   132        lifecycle {
   133          hook = "poststop"
   134        }
   135  
   136        driver = "docker"
   137  
   138        config {
   139          image   = "busybox:1"
   140          command = "/bin/sh"
   141          args    = ["local/poststop.sh"]
   142        }
   143  
   144        template {
   145          data = <<EOT
   146  #!/bin/sh
   147  sleep 1
   148  touch ${NOMAD_ALLOC_DIR}/poststop-ran
   149  touch ${NOMAD_ALLOC_DIR}/poststop-running
   150  touch ${NOMAD_ALLOC_DIR}/poststop-started
   151  sleep 5
   152  
   153  if [ ! -f ${NOMAD_ALLOC_DIR}/init-ran ]; then exit 12; fi
   154  if [ ! -f ${NOMAD_ALLOC_DIR}/main-started ]; then exit 15; fi
   155  if [ -f ${NOMAD_ALLOC_DIR}/init-running ]; then exit 14; fi
   156  if [ -f ${NOMAD_ALLOC_DIR}/main-running ]; then exit 17; fi
   157  rm ${NOMAD_ALLOC_DIR}/poststop-running
   158  EOT
   159  
   160          destination = "local/poststop.sh"
   161        }
   162  
   163        resources {
   164          cpu    = 64
   165          memory = 64
   166        }
   167      }
   168    }
   169  }