github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/drivers/exec.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Drivers: Exec'
     4  sidebar_title: Isolated Fork/Exec
     5  description: The Exec task driver is used to run binaries using OS isolation primitives.
     6  ---
     7  
     8  # Isolated Fork/Exec Driver
     9  
    10  Name: `exec`
    11  
    12  The `exec` driver is used to simply execute a particular command for a task.
    13  However, unlike [`raw_exec`](/docs/drivers/raw_exec) it uses the underlying isolation
    14  primitives of the operating system to limit the task's access to resources. While
    15  simple, since the `exec` driver can invoke any command, it can be used to call
    16  scripts or other wrappers which provide higher level features.
    17  
    18  ## Task Configuration
    19  
    20  ```hcl
    21  task "webservice" {
    22    driver = "exec"
    23  
    24    config {
    25      command = "my-binary"
    26      args    = ["-flag", "1"]
    27    }
    28  }
    29  ```
    30  
    31  The `exec` driver supports the following configuration in the job spec:
    32  
    33  - `command` - The command to execute. Must be provided. If executing a binary
    34    that exists on the host, the path must be absolute and within the task's
    35    [chroot](#chroot). If executing a binary that is downloaded from
    36    an [`artifact`](/docs/job-specification/artifact), the path can be
    37    relative from the allocations's root directory.
    38  
    39  - `args` - (Optional) A list of arguments to the `command`. References
    40    to environment variables or any [interpretable Nomad
    41    variables](/docs/runtime/interpolation) will be interpreted before
    42    launching the task.
    43  
    44  ## Examples
    45  
    46  To run a binary present on the Node:
    47  
    48  ```hcl
    49  task "example" {
    50    driver = "exec"
    51  
    52    config {
    53      # When running a binary that exists on the host, the path must be absolute.
    54      command = "/bin/sleep"
    55      args    = ["1"]
    56    }
    57  }
    58  ```
    59  
    60  To execute a binary downloaded from an
    61  [`artifact`](/docs/job-specification/artifact):
    62  
    63  ```hcl
    64  task "example" {
    65    driver = "exec"
    66  
    67    config {
    68      command = "name-of-my-binary"
    69    }
    70  
    71    artifact {
    72      source = "https://internal.file.server/name-of-my-binary"
    73      options {
    74        checksum = "sha256:abd123445ds4555555555"
    75      }
    76    }
    77  }
    78  ```
    79  
    80  ## Client Requirements
    81  
    82  The `exec` driver can only be run when on Linux and running Nomad as root.
    83  `exec` is limited to this configuration because currently isolation of resources
    84  is only guaranteed on Linux. Further, the host must have cgroups mounted properly
    85  in order for the driver to work.
    86  
    87  If you are receiving the error:
    88  
    89  ```
    90  * Constraint "missing drivers" filtered <> nodes
    91  ```
    92  
    93  and using the exec driver, check to ensure that you are running Nomad as root.
    94  This also applies for running Nomad in -dev mode.
    95  
    96  ## Plugin Options
    97  
    98  - `no_pivot_root` - Defaults to `false`. When `true`, the driver uses `chroot`
    99    for file system isolation without `pivot_root`. This is useful for systems
   100    where the root is on a ramdisk.
   101  
   102  ## Client Attributes
   103  
   104  The `exec` driver will set the following client attributes:
   105  
   106  - `driver.exec` - This will be set to "1", indicating the driver is available.
   107  
   108  ## Resource Isolation
   109  
   110  The resource isolation provided varies by the operating system of
   111  the client and the configuration.
   112  
   113  On Linux, Nomad will use cgroups, and a chroot to isolate the
   114  resources of a process and as such the Nomad agent must be run as root.
   115  
   116  ### Chroot
   117  
   118  The chroot is populated with data in the following directories from the host
   119  machine:
   120  
   121  ```
   122  [
   123    "/bin",
   124    "/etc",
   125    "/lib",
   126    "/lib32",
   127    "/lib64",
   128    "/run/resolvconf",
   129    "/sbin",
   130    "/usr",
   131  ]
   132  ```
   133  
   134  The task's chroot is populated by linking or copying the data from the host into
   135  the chroot. Note that this can take considerable disk space. Since Nomad v0.5.3,
   136  the client manages garbage collection locally which mitigates any issue this may
   137  create.
   138  
   139  This list is configurable through the agent client
   140  [configuration file](/docs/configuration/client#chroot_env).