Files
nomad/website/content/docs/job-specification/change_script.mdx
Aimee Ukasick 986f3c727a Docs: SEO job spec section (#25612)
* action page

* change all page_title fields

* update title

* constraint through migrate pages

* update page title and heading to use sentence case

* fix front matter description

* Apply suggestions from code review

Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>

---------

Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>
2025-05-19 09:02:07 -05:00

87 lines
2.5 KiB
Plaintext

---
layout: docs
page_title: change_script block in the job specification
description: |-
Configure template change scripts in the `change_script` block of the Nomad job specification. Nomad executes these scripts when a template changes. Configure the command, arguments, and timeout. Enable fail on error. Review an example of how to embed a script in the data block of a template block.
---
# `change_script` block in the job specification
<Placement groups={['job', 'group', 'task', 'template', 'change_script']} />
The `change_script` block allows operators to configure scripts that
will be executed on template change. This block 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.
### Example
Below is an example of how a script can be embedded in a `data` block of another
`template` block:
```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"
}
}
}
}
```