github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/job-specification/lifecycle.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: lifecycle Stanza - Job Specification
     4  sidebar_title: lifecycle
     5  description: |-
     6    The "lifecycle" stanza configures when a task is run within the lifecycle of a
     7    task group
     8  ---
     9  
    10  # `lifecycle` Stanza
    11  
    12  <Placement groups={['job', 'group', 'task', 'lifecycle']} />
    13  
    14  The `lifecycle` stanza is used to express task dependencies in Nomad and
    15  configures when a task is run within the lifecycle of a task group.
    16  
    17  Main tasks are tasks that do not have a `lifecycle` stanza. Lifecycle task hooks
    18  are run in relation to the main tasks. Tasks can be run as Prestart Hooks, which
    19  ensures the prestart task is run before the main tasks are run.
    20  
    21  Tasks can be run with an additional parameter to indicate that they are
    22  sidecars, which ensures that they are running over the duration of the whole
    23  task group. This will allow you to run a long-lived task in a task group for a
    24  batch job. The absence of the sidecar flag indicates that the task is ephemeral
    25  and the task will not be restarted if it completes successfully. This allows you
    26  to run an ephemeral prestart task in a task group for a service job, which can
    27  serve as initialization that occurs before the main services are started.
    28  
    29  Learn more about Nomad's task dependencies on the [HashiCorp Learn website][learn-taskdeps].
    30  
    31  
    32  ```hcl
    33  job "docs" {
    34    group "example" {
    35  
    36      task "init" {
    37        lifecycle {
    38          hook    = "prestart"
    39        }
    40        ...
    41      }
    42  
    43      task "logging" {
    44        lifecycle {
    45          hook    = "prestart"
    46          sidecar = true
    47        }
    48        ...
    49      }
    50  
    51      task "main" {
    52        ...
    53      }
    54  
    55    }
    56  }
    57  ```
    58  
    59  ## `lifecycle` Parameters
    60  
    61  - `hook` `(string: "prestart")` - Specifies when a task should be run within
    62    the lifecycle of a group. Currently only Prestart Hooks are supported.
    63  
    64  - `sidecar` `(bool: false)` - Controls whether or not a task is ephemeral or
    65    long-lived within the task group. If a lifecycle task is ephemeral (`sidecar =
    66    false`), the task will not be restarted after it completes successfully. If a
    67    lifecycle task is long-lived (`sidecar = true`) and it terminates, it will be
    68    restarted as long as the task group is running in its allocation.
    69  
    70  [learn-taskdeps]: https://learn.hashicorp.com/nomad?track=task-deps&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS#task-deps