open-nomad/website/content/docs/job-specification/change_script.mdx
quoing ce7a3745d5
docs: template change script example correction (#14368)
"path" parameter doesn't work, should be command
2022-08-30 12:09:55 +02:00

86 lines
2.3 KiB
Plaintext

---
layout: docs
page_title: change_script Stanza - Job Specification
description: The "change_script" stanza configures a script to be run on template re-render.
---
# `change_script` Stanza
<Placement groups={['job', 'group', 'task', 'template', 'change_script']} />
The `change_script` stanza allows operators to configure scripts that
will be executed on template change. This stanza is only used when template
`change_mode` is set to `script`.
```hcl
job "docs" {
group "example" {
task "server" {
template {
source = "local/redis.conf.tpl"
destination = "local/redis.conf"
change_mode = "script"
change_script {
command = "/bin/foo"
args = ["-verbose", "-debug"]
timeout = "5s"
fail_on_error = false
}
}
}
}
}
```
## `change_script` Parameters
- `command` `(string: "")` - Specifies the full path to a script or executable
that is to be executed on template change. The command must return exit code 0
to be considered successful. Path is relative to the driver, e.g., if running
with a container driver the path must be existing in the container. This option
is required if `change_mode` is `script`.
- `args` `(array<string>: [])` - List of arguments that are passed to the script
that is to be executed on template change.
- `timeout` `(string: "5s")` - Timeout for script execution specified using a
label suffix like `"30s"` or `"1h"`.
- `fail_on_error` `(bool: false)` - If `true`, Nomad will kill the task if the
script execution fails. If `false`, script failure will be logged but the task
will continue uninterrupted.
### Template as a script example
Below is an example of how a script can be embedded in a `data` block of another
`template` stanza:
```hcl
job "docs" {
group "example" {
task "server" {
template {
data = "{{key \"my_key\"}}"
destination = "local/test"
change_mode = "script"
change_script {
command = "/local/script.sh"
}
}
template {
data = <<EOF
#!/usr/bin/env bash
echo "Running change_mode script"
sleep 10
echo "Done"
EOF
destination = "local/script.sh"
perms = "777"
}
}
}
}
```