github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/change_script.mdx (about) 1 --- 2 layout: docs 3 page_title: change_script Stanza - Job Specification 4 description: The "change_script" stanza configures a script to be run on template re-render. 5 --- 6 7 # `change_script` Stanza 8 9 <Placement groups={['job', 'group', 'task', 'template', 'change_script']} /> 10 11 The `change_script` stanza allows operators to configure scripts that 12 will be executed on template change. This stanza is only used when template 13 `change_mode` is set to `script`. 14 15 ```hcl 16 job "docs" { 17 group "example" { 18 task "server" { 19 template { 20 source = "local/redis.conf.tpl" 21 destination = "local/redis.conf" 22 change_mode = "script" 23 change_script { 24 command = "/bin/foo" 25 args = ["-verbose", "-debug"] 26 timeout = "5s" 27 fail_on_error = false 28 } 29 } 30 } 31 } 32 } 33 ``` 34 35 ## `change_script` Parameters 36 37 - `command` `(string: "")` - Specifies the full path to a script or executable 38 that is to be executed on template change. The command must return exit code 0 39 to be considered successful. Path is relative to the driver, e.g., if running 40 with a container driver the path must be existing in the container. This option 41 is required if `change_mode` is `script`. 42 43 - `args` `(array<string>: [])` - List of arguments that are passed to the script 44 that is to be executed on template change. 45 46 - `timeout` `(string: "5s")` - Timeout for script execution specified using a 47 label suffix like `"30s"` or `"1h"`. 48 49 - `fail_on_error` `(bool: false)` - If `true`, Nomad will kill the task if the 50 script execution fails. If `false`, script failure will be logged but the task 51 will continue uninterrupted. 52 53 ### Template as a script example 54 55 Below is an example of how a script can be embedded in a `data` block of another 56 `template` stanza: 57 58 ```hcl 59 job "docs" { 60 group "example" { 61 task "server" { 62 template { 63 data = "{{key \"my_key\"}}" 64 destination = "local/test" 65 change_mode = "script" 66 67 change_script { 68 command = "/local/script.sh" 69 } 70 } 71 72 template { 73 data = <<EOF 74 #!/usr/bin/env bash 75 echo "Running change_mode script" 76 sleep 10 77 echo "Done" 78 EOF 79 destination = "local/script.sh" 80 perms = "777" 81 } 82 } 83 } 84 } 85 ```