2015-09-20 22:31:33 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Drivers: Exec"
|
|
|
|
sidebar_current: "docs-drivers-exec"
|
|
|
|
description: |-
|
|
|
|
The Exec task driver is used to run binaries using OS isolation primitives.
|
|
|
|
---
|
|
|
|
|
2015-10-08 18:36:22 +00:00
|
|
|
# Isolated Fork/Exec Driver
|
2015-09-20 22:31:33 +00:00
|
|
|
|
|
|
|
Name: `exec`
|
|
|
|
|
2015-09-20 22:42:33 +00:00
|
|
|
The `exec` driver is used to simply execute a particular command for a task.
|
2015-11-03 20:57:39 +00:00
|
|
|
However, unlike [`raw_exec`](raw_exec.html) it uses the underlying isolation
|
2016-08-27 12:56:39 +00:00
|
|
|
primitives of the operating system to limit the task's access to resources. While
|
2015-10-08 19:18:44 +00:00
|
|
|
simple, since the `exec` driver can invoke any command, it can be used to call
|
|
|
|
scripts or other wrappers which provide higher level features.
|
2015-09-20 22:42:33 +00:00
|
|
|
|
|
|
|
## Task Configuration
|
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
```hcl
|
|
|
|
task "webservice" {
|
|
|
|
driver = "exec"
|
|
|
|
|
|
|
|
config {
|
|
|
|
command = "my-binary"
|
|
|
|
args = ["-flag", "1"]
|
|
|
|
}
|
2016-10-28 00:36:26 +00:00
|
|
|
}
|
2016-10-03 21:35:20 +00:00
|
|
|
```
|
|
|
|
|
2015-09-20 22:42:33 +00:00
|
|
|
The `exec` driver supports the following configuration in the job spec:
|
|
|
|
|
2016-03-16 16:56:04 +00:00
|
|
|
* `command` - The command to execute. Must be provided. If executing a binary
|
|
|
|
that exists on the host, the path must be absolute. If executing a binary that
|
2016-10-28 00:36:26 +00:00
|
|
|
is downloaded from an [`artifact`](/docs/job-specification/artifact.html), the
|
2016-03-16 16:56:04 +00:00
|
|
|
path can be relative from the allocations's root directory.
|
2015-11-18 23:16:42 +00:00
|
|
|
|
2016-10-11 19:52:50 +00:00
|
|
|
* `args` - (Optional) A list of arguments to the `command`. References
|
2016-10-03 21:35:20 +00:00
|
|
|
to environment variables or any [interpretable Nomad
|
2016-10-28 00:36:26 +00:00
|
|
|
variables](/docs/runtime/interpolation.html) will be interpreted before
|
2016-10-03 21:35:20 +00:00
|
|
|
launching the task.
|
2015-09-20 22:42:33 +00:00
|
|
|
|
2015-10-15 21:40:08 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
To run a binary present on the Node:
|
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
```hcl
|
|
|
|
task "example" {
|
|
|
|
driver = "exec"
|
2016-03-16 16:56:04 +00:00
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
config {
|
|
|
|
# When running a binary that exists on the host, the path must be absolute.
|
|
|
|
command = "/bin/sleep"
|
|
|
|
args = ["1"]
|
2015-10-15 21:40:08 +00:00
|
|
|
}
|
2016-10-03 21:35:20 +00:00
|
|
|
}
|
2015-10-15 21:40:08 +00:00
|
|
|
```
|
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
To execute a binary downloaded from an
|
2016-10-28 00:36:26 +00:00
|
|
|
[`artifact`](/docs/job-specification/artifact.html):
|
2015-10-15 21:40:08 +00:00
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
```hcl
|
|
|
|
task "example" {
|
|
|
|
driver = "exec"
|
2016-03-16 16:56:04 +00:00
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
config {
|
|
|
|
command = "name-of-my-binary"
|
|
|
|
}
|
2016-03-16 16:56:04 +00:00
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
artifact {
|
|
|
|
source = "https://internal.file.server/name-of-my-binary"
|
|
|
|
options {
|
|
|
|
checksum = "sha256:abd123445ds4555555555"
|
2016-03-16 16:56:04 +00:00
|
|
|
}
|
2015-10-15 21:40:08 +00:00
|
|
|
}
|
2016-10-03 21:35:20 +00:00
|
|
|
}
|
2015-10-15 21:40:08 +00:00
|
|
|
```
|
|
|
|
|
2016-03-16 16:56:04 +00:00
|
|
|
## Client Requirements
|
|
|
|
|
|
|
|
The `exec` driver can only be run when on Linux and running Nomad as root.
|
|
|
|
`exec` is limited to this configuration because currently isolation of resources
|
2016-08-27 12:56:39 +00:00
|
|
|
is only guaranteed on Linux. Further, the host must have cgroups mounted properly
|
2016-03-16 16:56:04 +00:00
|
|
|
in order for the driver to work.
|
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
If you are receiving the error:
|
|
|
|
|
|
|
|
```
|
|
|
|
* Constraint "missing drivers" filtered <> nodes
|
|
|
|
```
|
|
|
|
|
|
|
|
and using the exec driver, check to ensure that you are running Nomad as root.
|
|
|
|
This also applies for running Nomad in -dev mode.
|
2016-03-16 16:56:04 +00:00
|
|
|
|
|
|
|
|
2015-09-20 22:42:33 +00:00
|
|
|
## Client Attributes
|
|
|
|
|
|
|
|
The `exec` driver will set the following client attributes:
|
|
|
|
|
2016-10-03 21:00:32 +00:00
|
|
|
* `driver.exec` - This will be set to "1", indicating the driver is available.
|
|
|
|
|
2015-09-20 22:42:33 +00:00
|
|
|
## Resource Isolation
|
|
|
|
|
|
|
|
The resource isolation provided varies by the operating system of
|
|
|
|
the client and the configuration.
|
|
|
|
|
2015-11-03 20:57:39 +00:00
|
|
|
On Linux, Nomad will use cgroups, and a chroot to isolate the
|
2015-09-23 01:31:13 +00:00
|
|
|
resources of a process and as such the Nomad agent must be run as root.
|
2016-01-21 23:02:51 +00:00
|
|
|
|
2016-08-05 22:59:06 +00:00
|
|
|
### <a id="chroot"></a>Chroot
|
2016-08-27 12:56:39 +00:00
|
|
|
The chroot is populated with data in the following directories from the host
|
2016-01-21 23:02:51 +00:00
|
|
|
machine:
|
|
|
|
|
2016-10-03 21:35:20 +00:00
|
|
|
```
|
|
|
|
[
|
|
|
|
"/bin",
|
|
|
|
"/etc",
|
|
|
|
"/lib",
|
|
|
|
"/lib32",
|
|
|
|
"/lib64",
|
|
|
|
"/run/resolvconf",
|
|
|
|
"/sbin",
|
|
|
|
"/usr",
|
|
|
|
]
|
|
|
|
```
|
2016-08-05 22:59:06 +00:00
|
|
|
|
|
|
|
This list is configurable through the agent client
|
2016-11-01 12:53:13 +00:00
|
|
|
[configuration file](/docs/agent/configuration/client.html#chroot_env).
|