Skip to content

Commit

Permalink
Merge pull request #5989 from hashicorp/d-fix-bashism-text
Browse files Browse the repository at this point in the history
Clarify script checks requiring shell
  • Loading branch information
Mahmood Ali authored Jul 22, 2019
2 parents 1a3483c + 623ada8 commit 037d613
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions website/source/docs/job-specification/service.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,45 +268,39 @@ resources {
}
```

### Check with Bash-isms
### Script Checks with Shells

This example shows a common mistake and correct behavior for custom checks.
Suppose a health check like this:

```shell
$ test -f /tmp/file.txt
```

In this example `test` is not actually a command (binary) on the system; it is a
built-in shell function to bash. Thus, the following **would not work**:
This example shows a service with a script check that is evaluated and interpolated in a shell; it
tests whether a file is present at `${HEALTH_CHECK_FILE}` environment variable:

```hcl
service {
check {
type = "script"
command = "test -f /tmp/file.txt" # THIS IS NOT CORRECT
command = "/bin/bash"
args = ["-c", "test -f ${HEALTH_CHECK_FILE}"]
}
}
```

Nomad will attempt to find an executable named `test` on your system, but it
does not exist. It is actually just a function of bash. Additionally, it is not
possible to specify the arguments in a single string. Here is the correct
solution:
Using `/bin/bash` (or another shell) is required here to interpolate the `${HEALTH_CHECK_FILE}` value.

The following examples of `command` fields **will not work**:

```hcl
service {
check {
type = "script"
command = "/bin/bash"
args = ["-c", "test -f /tmp/file.txt"]
}
# invalid because command is not a path
check {
type = "script"
command = "test -f /tmp/file.txt"
}
```
The `command` is actually `/bin/bash`, since that is the actual process we are
running. The arguments to that command are the script itself, which each
argument provided as a value to the `args` array.
# invalid because path will not be interpolated
check {
type = "script"
command = "/bin/test"
args = ["-f", "${HEALTH_CHECK_FILE}"]
}
```

### HTTP Health Check

Expand Down

0 comments on commit 037d613

Please sign in to comment.