github.com/anuvu/nomad@v0.8.7-atom1/website/source/api/json-jobs.html.md (about) 1 --- 2 layout: api 3 page_title: JSON Job Specification - HTTP API 4 sidebar_current: api-json-jobs 5 description: |- 6 Jobs can also be specified via the HTTP API using a JSON format. This guide 7 discusses the job specification in JSON format. 8 --- 9 10 # JSON Job Specification 11 12 This guide covers the JSON syntax for submitting jobs to Nomad. A useful command 13 for generating valid JSON versions of HCL jobs is: 14 15 ```shell 16 $ nomad job run -output my-job.nomad 17 ``` 18 19 ## Syntax 20 21 Below is the JSON representation of the job outputted by `$ nomad init`: 22 23 ```json 24 { 25 "Job": { 26 "ID": "example", 27 "Name": "example", 28 "Type": "service", 29 "Priority": 50, 30 "Datacenters": [ 31 "dc1" 32 ], 33 "TaskGroups": [{ 34 "Name": "cache", 35 "Count": 1, 36 "Migrate": { 37 "HealthCheck": "checks", 38 "HealthyDeadline": 300000000000, 39 "MaxParallel": 1, 40 "MinHealthyTime": 10000000000 41 }, 42 "Tasks": [{ 43 "Name": "redis", 44 "Driver": "docker", 45 "User": "", 46 "Config": { 47 "image": "redis:3.2", 48 "port_map": [{ 49 "db": 6379 50 }] 51 }, 52 "Services": [{ 53 "Id": "", 54 "Name": "redis-cache", 55 "Tags": [ 56 "global", 57 "cache" 58 ], 59 "PortLabel": "db", 60 "AddressMode": "", 61 "Checks": [{ 62 "Id": "", 63 "Name": "alive", 64 "Type": "tcp", 65 "Command": "", 66 "Args": null, 67 "Header": {}, 68 "Method": "", 69 "Path": "", 70 "Protocol": "", 71 "PortLabel": "", 72 "Interval": 10000000000, 73 "Timeout": 2000000000, 74 "InitialStatus": "", 75 "TLSSkipVerify": false, 76 "CheckRestart": { 77 "Limit": 3, 78 "Grace": 30000000000, 79 "IgnoreWarnings": false 80 } 81 }] 82 }], 83 "Resources": { 84 "CPU": 500, 85 "MemoryMB": 256, 86 "Networks": [{ 87 "Device": "", 88 "CIDR": "", 89 "IP": "", 90 "MBits": 10, 91 "DynamicPorts": [{ 92 "Label": "db", 93 "Value": 0 94 }] 95 }] 96 }, 97 "Leader": false 98 }], 99 "RestartPolicy": { 100 "Interval": 1800000000000, 101 "Attempts": 2, 102 "Delay": 15000000000, 103 "Mode": "fail" 104 }, 105 "ReschedulePolicy": { 106 "Attempts": 10, 107 "Delay": 30000000000, 108 "DelayFunction": "exponential", 109 "Interval": 0, 110 "MaxDelay": 3600000000000, 111 "Unlimited": true 112 }, 113 "EphemeralDisk": { 114 "SizeMB": 300 115 } 116 }], 117 "Update": { 118 "MaxParallel": 1, 119 "MinHealthyTime": 10000000000, 120 "HealthyDeadline": 180000000000, 121 "AutoRevert": false, 122 "Canary": 0 123 } 124 } 125 } 126 ``` 127 128 The example JSON could be submitted as a job using the following: 129 130 ```text 131 $ curl -XPUT -d @example.json http://127.0.0.1:4646/v1/job/example 132 { 133 "EvalID": "5d6ded54-0b2a-8858-6583-be5f476dec9d", 134 "EvalCreateIndex": 12, 135 "JobModifyIndex": 11, 136 "Warnings": "", 137 "Index": 12, 138 "LastContact": 0, 139 "KnownLeader": false 140 } 141 ``` 142 143 ## Syntax Reference 144 145 Following is a syntax reference for the possible keys that are supported and 146 their default values if any for each type of object. 147 148 ### Job 149 150 The `Job` object supports the following keys: 151 152 - `AllAtOnce` - Controls whether the scheduler can make partial placements if 153 optimistic scheduling resulted in an oversubscribed node. This does not 154 control whether all allocations for the job, where all would be the desired 155 count for each task group, must be placed atomically. This should only be 156 used for special circumstances. Defaults to `false`. 157 158 - `Constraints` - A list to define additional constraints where a job can be 159 run. See the constraint reference for more details. 160 161 - `Datacenters` - A list of datacenters in the region which are eligible 162 for task placement. This must be provided, and does not have a default. 163 164 - `TaskGroups` - A list to define additional task groups. See the task group 165 reference for more details. 166 167 - `Meta` - Annotates the job with opaque metadata. 168 169 - `Namespace` - The namespace to execute the job in, defaults to "default". 170 Values other than default are not allowed in non-Enterprise versions of Nomad. 171 172 - `ParameterizedJob` - Specifies the job as a parameterized job such that it can 173 be dispatched against. The `ParameterizedJob` object supports the following 174 attributes: 175 176 - `MetaOptional` - Specifies the set of metadata keys that may be provided 177 when dispatching against the job as a string array. 178 179 - `MetaRequired` - Specifies the set of metadata keys that must be provided 180 when dispatching against the job as a string array. 181 182 - `Payload` - Specifies the requirement of providing a payload when 183 dispatching against the parameterized job. The options for this field are 184 "optional", "required" and "forbidden". The default value is "optional". 185 186 - `Payload` - The payload may not be set when submitting a job but may appear in 187 a dispatched job. The `Payload` will be a base64 encoded string containing the 188 payload that the job was dispatched with. The `payload` has a **maximum size 189 of 16 KiB**. 190 191 - `Priority` - Specifies the job priority which is used to prioritize 192 scheduling and access to resources. Must be between 1 and 100 inclusively, 193 and defaults to 50. 194 195 - `Region` - The region to run the job in, defaults to "global". 196 197 - `Type` - Specifies the job type and switches which scheduler 198 is used. Nomad provides the `service`, `system` and `batch` schedulers, 199 and defaults to `service`. To learn more about each scheduler type visit 200 [here](/docs/runtime/schedulers.html) 201 202 - `Update` - Specifies an update strategy to be applied to all task groups 203 within the job. When specified both at the job level and the task group level, 204 the update blocks are merged with the task group's taking precedence. For more 205 details on the update stanza, please see below. 206 207 - `Periodic` - `Periodic` allows the job to be scheduled at fixed times, dates 208 or intervals. The periodic expression is always evaluated in the UTC 209 timezone to ensure consistent evaluation when Nomad Servers span multiple 210 time zones. The `Periodic` object is optional and supports the following attributes: 211 212 - `Enabled` - `Enabled` determines whether the periodic job will spawn child 213 jobs. 214 215 - `TimeZone` - Specifies the time zone to evaluate the next launch interval 216 against. This is useful when wanting to account for day light savings in 217 various time zones. The time zone must be parsable by Golang's 218 [LoadLocation](https://golang.org/pkg/time/#LoadLocation). The default is 219 UTC. 220 221 - `SpecType` - `SpecType` determines how Nomad is going to interpret the 222 periodic expression. `cron` is the only supported `SpecType` currently. 223 224 - `Spec` - A cron expression configuring the interval the job is launched 225 at. Supports predefined expressions such as "@daily" and "@weekly" See 226 [here](https://github.com/gorhill/cronexpr#implementation) for full 227 documentation of supported cron specs and the predefined expressions. 228 229 - <a id="prohibit_overlap">`ProhibitOverlap`</a> - `ProhibitOverlap` can 230 be set to true to enforce that the periodic job doesn't spawn a new 231 instance of the job if any of the previous jobs are still running. It is 232 defaulted to false. 233 234 An example `periodic` block: 235 236 ```json 237 { 238 "Periodic": { 239 "Spec": "*/15 - *", 240 "TimeZone": "Europe/Berlin", 241 "SpecType": "cron", 242 "Enabled": true, 243 "ProhibitOverlap": true 244 } 245 } 246 ``` 247 248 - `ReschedulePolicy` - Specifies a reschedule policy to be applied to all task groups 249 within the job. When specified both at the job level and the task group level, 250 the reschedule blocks are merged, with the task group's taking precedence. For more 251 details on `ReschedulePolicy`, please see below. 252 253 ### Task Group 254 255 `TaskGroups` is a list of `TaskGroup` objects, each supports the following 256 attributes: 257 258 - `Constraints` - This is a list of `Constraint` objects. See the constraint 259 reference for more details. 260 261 - `Count` - Specifies the number of the task groups that should 262 be running. Must be non-negative, defaults to one. 263 264 - `Meta` - A key-value map that annotates the task group with opaque metadata. 265 266 - `Migrate` - Specifies a migration strategy to be applied during [node 267 drains][drain]. 268 269 - `HealthCheck` - One of `checks` or `task_states`. Indicates how task health 270 should be determined: either via Consul health checks or whether the task 271 was able to run successfully. 272 273 - `HealthyDeadline` - Specifies duration a task must become healthy within 274 before it is considered unhealthy. 275 276 - `MaxParallel` - Specifies how many allocations may be migrated at once. 277 278 - `MinHealthyTime` - Specifies duration a task must be considered healthy 279 before the migration is considered healthy. 280 281 - `Name` - The name of the task group. Must be specified. 282 283 - `RestartPolicy` - Specifies the restart policy to be applied to tasks in this group. 284 If omitted, a default policy for batch and non-batch jobs is used based on the 285 job type. See the [restart policy reference](#restart_policy) for more details. 286 287 - `ReschedulePolicy` - Specifies the reschedule policy to be applied to tasks in this group. 288 If omitted, a default policy is used for batch and service jobs. System jobs are not eligible 289 for rescheduling. See the [reschedule policy reference](#reschedule_policy) for more details. 290 291 - `EphemeralDisk` - Specifies the group's ephemeral disk requirements. See the 292 [ephemeral disk reference](#ephemeral_disk) for more details. 293 294 - `Update` - Specifies an update strategy to be applied to all task groups 295 within the job. When specified both at the job level and the task group level, 296 the update blocks are merged with the task group's taking precedence. For more 297 details on the update stanza, please see below. 298 299 - `Tasks` - A list of `Task` object that are part of the task group. 300 301 ### Task 302 303 The `Task` object supports the following keys: 304 305 - `Artifacts` - `Artifacts` is a list of `Artifact` objects which define 306 artifacts to be downloaded before the task is run. See the artifacts 307 reference for more details. 308 309 - `Config` - A map of key-value configuration passed into the driver 310 to start the task. The details of configurations are specific to 311 each driver. 312 313 - `Constraints` - This is a list of `Constraint` objects. See the constraint 314 reference for more details. 315 316 - `DispatchPayload` - Configures the task to have access to dispatch payloads. 317 The `DispatchPayload` object supports the following attributes: 318 319 - `File` - Specifies the file name to write the content of dispatch payload 320 to. The file is written relative to the task's local directory. 321 322 - `Driver` - Specifies the task driver that should be used to run the 323 task. See the [driver documentation](/docs/drivers/index.html) for what 324 is available. Examples include `docker`, `qemu`, `java`, and `exec`. 325 326 - `Env` - A map of key-value representing environment variables that 327 will be passed along to the running process. Nomad variables are 328 interpreted when set in the environment variable values. See the table of 329 interpreted variables [here](/docs/runtime/interpolation.html). 330 331 For example the below environment map will be reinterpreted: 332 333 ```json 334 { 335 "Env": { 336 "NODE_CLASS" : "${nomad.class}" 337 } 338 } 339 ``` 340 341 - `KillSignal` - Specifies a configurable kill signal for a task, where the 342 default is SIGINT. Note that this is only supported for drivers which accept 343 sending signals (currently `docker`, `exec`, `raw_exec`, and `java` drivers). 344 345 - `KillTimeout` - `KillTimeout` is a time duration in nanoseconds. It can be 346 used to configure the time between signaling a task it will be killed and 347 actually killing it. Drivers first sends a task the `SIGINT` signal and then 348 sends `SIGTERM` if the task doesn't die after the `KillTimeout` duration has 349 elapsed. The default `KillTimeout` is 5 seconds. 350 351 - `Leader` - Specifies whether the task is the leader task of the task group. If 352 set to true, when the leader task completes, all other tasks within the task 353 group will be gracefully shutdown. 354 355 - `LogConfig` - This allows configuring log rotation for the `stdout` and `stderr` 356 buffers of a Task. See the log rotation reference below for more details. 357 358 - `Meta` - Annotates the task group with opaque metadata. 359 360 - `Name` - The name of the task. This field is required. 361 362 - `Resources` - Provides the resource requirements of the task. 363 See the resources reference for more details. 364 365 - `Services` - `Services` is a list of `Service` objects. Nomad integrates with 366 Consul for service discovery. A `Service` object represents a routable and 367 discoverable service on the network. Nomad automatically registers when a task 368 is started and de-registers it when the task transitions to the dead state. 369 [Click here](/docs/service-discovery/index.html) to learn more about 370 services. Below is the fields in the `Service` object: 371 372 - `Name`: An explicit name for the Service. Nomad will replace `${JOB}`, 373 `${TASKGROUP}` and `${TASK}` by the name of the job, task group or task, 374 respectively. `${BASE}` expands to the equivalent of 375 `${JOB}-${TASKGROUP}-${TASK}`, and is the default name for a Service. 376 Each service defined for a given task must have a distinct name, so if 377 a task has multiple services only one of them can use the default name 378 and the others must be explicitly named. Names must adhere to 379 [RFC-1123 ยง2.1](https://tools.ietf.org/html/rfc1123#section-2) and are 380 limited to alphanumeric and hyphen characters (i.e. `[a-z0-9\-]`), and be 381 less than 64 characters in length. 382 383 - `Tags`: A list of string tags associated with this Service. String 384 interpolation is supported in tags. 385 386 - `CanaryTags`: A list of string tags associated with this Service while it 387 is a canary. Once the canary is promoted, the registered tags will be 388 updated to the set defined in the `Tags` field. String interpolation is 389 supported in tags. 390 391 - `PortLabel`: `PortLabel` is an optional string and is used to associate 392 a port with the service. If specified, the port label must match one 393 defined in the resources block. This could be a label of either a 394 dynamic or a static port. 395 396 - `AddressMode`: Specifies what address (host or driver-specific) this 397 service should advertise. This setting is supported in Docker since 398 Nomad 0.6 and rkt since Nomad 0.7. Valid options are: 399 400 - `auto` - Allows the driver to determine whether the host or driver 401 address should be used. Defaults to `host` and only implemented by 402 Docker. If you use a Docker network plugin such as weave, Docker will 403 automatically use its address. 404 405 - `driver` - Use the IP specified by the driver, and the port specified 406 in a port map. A numeric port may be specified since port maps aren't 407 required by all network plugins. Useful for advertising SDN and 408 overlay network addresses. Task will fail if driver network cannot be 409 determined. Only implemented for Docker and rkt. 410 411 - `host` - Use the host IP and port. 412 413 - `Checks`: `Checks` is an array of check objects. A check object defines a 414 health check associated with the service. Nomad supports the `script`, 415 `http` and `tcp` Consul Checks. Script checks are not supported for the 416 qemu driver since the Nomad client doesn't have access to the file system 417 of a task using the Qemu driver. 418 419 - `Type`: This indicates the check types supported by Nomad. Valid 420 options are currently `script`, `http` and `tcp`. 421 422 - `Name`: The name of the health check. 423 424 - `AddressMode`: Same as `AddressMode` on `Service`. Unlike services, 425 checks do not have an `auto` address mode as there's no way for 426 Nomad to know which is the best address to use for checks. Consul 427 needs access to the address for any HTTP or TCP checks. Added in 428 Nomad 0.7.1. Unlike `PortLabel`, this setting is *not* inherited 429 from the `Service`. 430 431 - `PortLabel`: Specifies the label of the port on which the check will 432 be performed. Note this is the _label_ of the port and not the port 433 number unless `AddressMode: "driver"`. The port label must match one 434 defined in the Network stanza. If a port value was declared on the 435 `Service`, this will inherit from that value if not supplied. If 436 supplied, this value takes precedence over the `Service.PortLabel` 437 value. This is useful for services which operate on multiple ports. 438 `http` and `tcp` checks require a port while `script` checks do not. 439 Checks will use the host IP and ports by default. In Nomad 0.7.1 or 440 later numeric ports may be used if `AddressMode: "driver"` is set on 441 the check. 442 443 - `Header`: Headers for HTTP checks. Should be an object where the 444 values are an array of values. Headers will be written once for each 445 value. 446 447 - `Interval`: This indicates the frequency of the health checks that 448 Consul will perform. 449 450 - `Timeout`: This indicates how long Consul will wait for a health 451 check query to succeed. 452 453 - `Method`: The HTTP method to use for HTTP checks. Defaults to GET. 454 455 - `Path`: The path of the HTTP endpoint which Consul will query to query 456 the health of a service if the type of the check is `http`. Nomad 457 will add the IP of the service and the port, users are only required 458 to add the relative URL of the health check endpoint. Absolute paths 459 are not allowed. 460 461 - `Protocol`: This indicates the protocol for the HTTP checks. Valid 462 options are `http` and `https`. We default it to `http`. 463 464 - `Command`: This is the command that the Nomad client runs for doing 465 script based health check. 466 467 - `Args`: Additional arguments to the `command` for script based health 468 checks. 469 470 - `TLSSkipVerify`: If true, Consul will not attempt to verify the 471 certificate when performing HTTPS checks. Requires Consul >= 0.7.2. 472 473 - `CheckRestart`: `CheckRestart` is an object which enables 474 restarting of tasks based upon Consul health checks. 475 476 - `Limit`: The number of unhealthy checks allowed before the 477 service is restarted. Defaults to `0` which disables 478 health-based restarts. 479 480 - `Grace`: The duration to wait after a task starts or restarts 481 before counting unhealthy checks count against the limit. 482 Defaults to "1s". 483 484 - `IgnoreWarnings`: Treat checks that are warning as passing. 485 Defaults to false which means warnings are considered unhealthy. 486 487 - `ShutdownDelay` - Specifies the duration to wait when killing a task between 488 removing it from Consul and sending it a shutdown signal. Ideally services 489 would fail healthchecks once they receive a shutdown signal. Alternatively 490 `ShutdownDelay` may be set to give in flight requests time to complete before 491 shutting down. 492 493 - `Templates` - Specifies the set of [`Template`](#template) objects to render for the task. 494 Templates can be used to inject both static and dynamic configuration with 495 data populated from environment variables, Consul and Vault. 496 497 - `User` - Set the user that will run the task. It defaults to the same user 498 the Nomad client is being run as. This can only be set on Linux platforms. 499 500 ### Resources 501 502 The `Resources` object supports the following keys: 503 504 - `CPU` - The CPU required in MHz. 505 506 - `IOPS` - The number of IOPS required given as a weight between 10-1000. 507 508 - `MemoryMB` - The memory required in MB. 509 510 - `Networks` - A list of network objects. 511 512 The Network object supports the following keys: 513 514 - `MBits` - The number of MBits in bandwidth required. 515 516 Nomad can allocate two types of ports to a task - Dynamic and Static/Reserved 517 ports. A network object allows the user to specify a list of `DynamicPorts` and 518 `ReservedPorts`. Each object supports the following attributes: 519 520 - `Value` - The port number for static ports. If the port is dynamic, then this 521 attribute is ignored. 522 - `Label` - The label to annotate a port so that it can be referred in the 523 service discovery block or environment variables. 524 525 <a id="ephemeral_disk"></a> 526 527 ### Ephemeral Disk 528 529 The `EphemeralDisk` object supports the following keys: 530 531 - `Migrate` - Specifies that the Nomad client should make a best-effort attempt 532 to migrate the data from a remote machine if placement cannot be made on the 533 original node. During data migration, the task will block starting until the 534 data migration has completed. Value is a boolean and the default is false. 535 536 - `SizeMB` - Specifies the size of the ephemeral disk in MB. Default is 300. 537 538 - `Sticky` - Specifies that Nomad should make a best-effort attempt to place the 539 updated allocation on the same machine. This will move the `local/` and 540 `alloc/data` directories to the new allocation. Value is a boolean and the 541 default is false. 542 543 <a id="reschedule_policy"></a> 544 545 ### Reschedule Policy 546 547 The `ReschedulePolicy` object supports the following keys: 548 549 - `Attempts` - `Attempts` is the number of reschedule attempts allowed 550 in an `Interval`. 551 552 - `Interval` - `Interval` is a time duration that is specified in nanoseconds. 553 The `Interval` is a sliding window within which at most `Attempts` number 554 of reschedule attempts are permitted. 555 556 - `Delay` - A duration to wait before attempting rescheduling. It is specified in 557 nanoseconds. 558 559 - `DelayFunction` - Specifies the function that is used to calculate subsequent reschedule delays. 560 The initial delay is specified by the `Delay` parameter. Allowed values for `DelayFunction` are listed below: 561 - `constant` - The delay between reschedule attempts stays at the `Delay` value. 562 - `exponential` - The delay between reschedule attempts doubles. 563 - `fibonacci` - The delay between reschedule attempts is calculated by adding the two most recent 564 delays applied. For example if `Delay` is set to 5 seconds, the next five reschedule attempts will be 565 delayed by 5 seconds, 5 seconds, 10 seconds, 15 seconds, and 25 seconds respectively. 566 567 - `MaxDelay` - `MaxDelay` is an upper bound on the delay beyond which it will not increase. This parameter is used when 568 `DelayFunction` is `exponential` or `fibonacci`, and is ignored when `constant` delay is used. 569 570 - `Unlimited` - `Unlimited` enables unlimited reschedule attempts. If this is set to true 571 the `Attempts` and `Interval` fields are not used. 572 573 574 <a id="restart_policy"></a> 575 576 ### Restart Policy 577 578 The `RestartPolicy` object supports the following keys: 579 580 - `Attempts` - `Attempts` is the number of restarts allowed in an `Interval`. 581 582 - `Interval` - `Interval` is a time duration that is specified in nanoseconds. 583 The `Interval` begins when the first task starts and ensures that only 584 `Attempts` number of restarts happens within it. If more than `Attempts` 585 number of failures happen, behavior is controlled by `Mode`. 586 587 - `Delay` - A duration to wait before restarting a task. It is specified in 588 nanoseconds. A random jitter of up to 25% is added to the delay. 589 590 - `Mode` - `Mode` is given as a string and controls the behavior when the task 591 fails more than `Attempts` times in an `Interval`. Possible values are listed 592 below: 593 594 - `delay` - `delay` will delay the next restart until the next `Interval` is 595 reached. 596 597 - `fail` - `fail` will not restart the task again. 598 599 ### Update 600 601 Specifies the task group update strategy. When omitted, rolling updates are 602 disabled. The update stanza can be specified at the job or task group level. 603 When specified at the job, the update stanza is inherited by all task groups. 604 When specified in both the job and in a task group, the stanzas are merged with 605 the task group's taking precedence. The `Update` object supports the following 606 attributes: 607 608 - `MaxParallel` - `MaxParallel` is given as an integer value and specifies 609 the number of tasks that can be updated at the same time. 610 611 - `HealthCheck` - Specifies the mechanism in which allocations health is 612 determined. The potential values are: 613 614 - "checks" - Specifies that the allocation should be considered healthy when 615 all of its tasks are running and their associated [checks][] are healthy, 616 and unhealthy if any of the tasks fail or not all checks become healthy. 617 This is a superset of "task_states" mode. 618 619 - "task_states" - Specifies that the allocation should be considered healthy 620 when all its tasks are running and unhealthy if tasks fail. 621 622 - "manual" - Specifies that Nomad should not automatically determine health 623 and that the operator will specify allocation health using the [HTTP 624 API](/api/deployments.html#set-allocation-health-in-deployment). 625 626 - `MinHealthyTime` - Specifies the minimum time the allocation must be in the 627 healthy state before it is marked as healthy and unblocks further allocations 628 from being updated. 629 630 - `HealthyDeadline` - Specifies the deadline in which the allocation must be 631 marked as healthy after which the allocation is automatically transitioned to 632 unhealthy. 633 634 - `ProgressDeadline` - Specifies the deadline in which an allocation must be 635 marked as healthy. The deadline begins when the first allocation for the 636 deployment is created and is reset whenever an allocation as part of the 637 deployment transitions to a healthy state. If no allocation transitions to the 638 healthy state before the progress deadline, the deployment is marked as 639 failed. If the `progress_deadline` is set to `0`, the first allocation to be 640 marked as unhealthy causes the deployment to fail. 641 642 - `AutoRevert` - Specifies if the job should auto-revert to the last stable job 643 on deployment failure. A job is marked as stable if all the allocations as 644 part of its deployment were marked healthy. 645 646 - `Canary` - Specifies that changes to the job that would result in destructive 647 updates should create the specified number of canaries without stopping any 648 previous allocations. Once the operator determines the canaries are healthy, 649 they can be promoted which unblocks a rolling update of the remaining 650 allocations at a rate of `max_parallel`. 651 652 - `Stagger` - Specifies the delay between migrating allocations off nodes marked 653 for draining. 654 655 An example `Update` block: 656 657 ```json 658 { 659 "Update": { 660 "MaxParallel": 3, 661 "HealthCheck": "checks", 662 "MinHealthyTime": 15000000000, 663 "HealthyDeadline": 180000000000, 664 "AutoRevert": false, 665 "Canary": 1 666 } 667 } 668 ``` 669 670 ### Constraint 671 672 The `Constraint` object supports the following keys: 673 674 - `LTarget` - Specifies the attribute to examine for the 675 constraint. See the table of attributes [here](/docs/runtime/interpolation.html#interpreted_node_vars). 676 677 - `RTarget` - Specifies the value to compare the attribute against. 678 This can be a literal value, another attribute or a regular expression if 679 the `Operator` is in "regexp" mode. 680 681 - `Operand` - Specifies the test to be performed on the two targets. It takes on the 682 following values: 683 684 - `regexp` - Allows the `RTarget` to be a regular expression to be matched. 685 686 - `set_contains` - Allows the `RTarget` to be a comma separated list of values 687 that should be contained in the LTarget's value. 688 689 - `distinct_hosts` - If set, the scheduler will not co-locate any task groups on the same 690 machine. This can be specified as a job constraint which applies the 691 constraint to all task groups in the job, or as a task group constraint which 692 scopes the effect to just that group. The constraint may not be 693 specified at the task level. 694 695 Placing the constraint at both the job level and at the task group level is 696 redundant since when placed at the job level, the constraint will be applied 697 to all task groups. When specified, `LTarget` and `RTarget` should be 698 omitted. 699 700 - `distinct_property` - If set, the scheduler selects nodes that have a 701 distinct value of the specified property. The `RTarget` specifies how 702 many allocations are allowed to share the value of a property. The 703 `RTarget` must be 1 or greater and if omitted, defaults to 1. This can 704 be specified as a job constraint which applies the constraint to all 705 task groups in the job, or as a task group constraint which scopes the 706 effect to just that group. The constraint may not be specified at the 707 task level. 708 709 Placing the constraint at both the job level and at the task group level is 710 redundant since when placed at the job level, the constraint will be applied 711 to all task groups. When specified, `LTarget` should be the property 712 that should be distinct and `RTarget` should be omitted. 713 714 - Comparison Operators - `=`, `==`, `is`, `!=`, `not`, `>`, `>=`, `<`, `<=`. The 715 ordering is compared lexically. 716 717 ### Log Rotation 718 719 The `LogConfig` object configures the log rotation policy for a task's `stdout` and 720 `stderr`. The `LogConfig` object supports the following attributes: 721 722 - `MaxFiles` - The maximum number of rotated files Nomad will retain for 723 `stdout` and `stderr`, each tracked individually. 724 725 - `MaxFileSizeMB` - The size of each rotated file. The size is specified in 726 `MB`. 727 728 If the amount of disk resource requested for the task is less than the total 729 amount of disk space needed to retain the rotated set of files, Nomad will return 730 a validation error when a job is submitted. 731 732 ```json 733 { 734 "LogConfig": { 735 "MaxFiles": 3, 736 "MaxFileSizeMB": 10 737 } 738 } 739 ``` 740 741 In the above example we have asked Nomad to retain 3 rotated files for both 742 `stderr` and `stdout` and size of each file is 10 MB. The minimum disk space that 743 would be required for the task would be 60 MB. 744 745 ### Artifact 746 747 Nomad downloads artifacts using 748 [`go-getter`](https://github.com/hashicorp/go-getter). The `go-getter` library 749 allows downloading of artifacts from various sources using a URL as the input 750 source. The key-value pairs given in the `options` block map directly to 751 parameters appended to the supplied `source` URL. These are then used by 752 `go-getter` to appropriately download the artifact. `go-getter` also has a CLI 753 tool to validate its URL and can be used to check if the Nomad `artifact` is 754 valid. 755 756 Nomad allows downloading `http`, `https`, and `S3` artifacts. If these artifacts 757 are archives (zip, tar.gz, bz2, etc.), these will be unarchived before the task 758 is started. 759 760 The `Artifact` object supports the following keys: 761 762 - `GetterSource` - The path to the artifact to download. 763 764 - `RelativeDest` - An optional path to download the artifact into relative to the 765 root of the task's directory. If omitted, it will default to `local/`. 766 767 - `GetterOptions` - A `map[string]string` block of options for `go-getter`. 768 Full documentation of supported options are available 769 [here](https://github.com/hashicorp/go-getter/tree/ef5edd3d8f6f482b775199be2f3734fd20e04d4a#protocol-specific-options-1). 770 An example is given below: 771 772 ```json 773 { 774 "GetterOptions": { 775 "checksum": "md5:c4aa853ad2215426eb7d70a21922e794", 776 777 "aws_access_key_id": "<id>", 778 "aws_access_key_secret": "<secret>", 779 "aws_access_token": "<token>" 780 } 781 } 782 ``` 783 784 An example of downloading and unzipping an archive is as simple as: 785 786 ```json 787 { 788 "Artifacts": [ 789 { 790 "GetterSource": "https://example.com/my.zip", 791 "GetterOptions": { 792 "checksum": "md5:7f4b3e3b4dd5150d4e5aaaa5efada4c3" 793 } 794 } 795 ] 796 } 797 ``` 798 799 #### S3 examples 800 801 S3 has several different types of addressing and more detail can be found 802 [here](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro) 803 804 S3 region specific endpoints can be found 805 [here](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) 806 807 Path based style: 808 809 ```json 810 { 811 "Artifacts": [ 812 { 813 "GetterSource": "https://s3-us-west-2.amazonaws.com/my-bucket-example/my_app.tar.gz", 814 } 815 ] 816 } 817 ``` 818 819 or to override automatic detection in the URL, use the S3-specific syntax 820 821 ```json 822 { 823 "Artifacts": [ 824 { 825 "GetterSource": "s3::https://s3-eu-west-1.amazonaws.com/my-bucket-example/my_app.tar.gz", 826 } 827 ] 828 } 829 ``` 830 831 Virtual hosted based style 832 833 ```json 834 { 835 "Artifacts": [ 836 { 837 "GetterSource": "my-bucket-example.s3-eu-west-1.amazonaws.com/my_app.tar.gz", 838 } 839 ] 840 } 841 ``` 842 843 ### Template 844 845 The `Template` block instantiates an instance of a template renderer. This 846 creates a convenient way to ship configuration files that are populated from 847 environment variables, Consul data, Vault secrets, or just general 848 configurations within a Nomad task. 849 850 Nomad utilizes a tool called [Consul Template][ct]. Since Nomad v0.5.3, the 851 template can reference [Nomad's runtime environment variables][env]. For a full 852 list of the API template functions, please refer to the [Consul Template 853 README][ct]. 854 855 856 `Template` object supports following attributes: 857 858 - `ChangeMode` - Specifies the behavior Nomad should take if the rendered 859 template changes. The default value is `"restart"`. The possible values are: 860 861 - `"noop"` - take no action (continue running the task) 862 - `"restart"` - restart the task 863 - `"signal"` - send a configurable signal to the task 864 865 - `ChangeSignal` - Specifies the signal to send to the task as a string like 866 "SIGUSR1" or "SIGINT". This option is required if the `ChangeMode` is 867 `signal`. 868 869 - `DestPath` - Specifies the location where the resulting template should be 870 rendered, relative to the task directory. 871 872 - `EmbeddedTmpl` - Specifies the raw template to execute. One of `SourcePath` 873 or `EmbeddedTmpl` must be specified, but not both. This is useful for smaller 874 templates, but we recommend using `SourcePath` for larger templates. 875 876 - `Envvars` - Specifies the template should be read back as environment 877 variables for the task. 878 879 - `LeftDelim` - Specifies the left delimiter to use in the template. The default 880 is "{{" for some templates, it may be easier to use a different delimiter that 881 does not conflict with the output file itself. 882 883 - `Perms` - Specifies the rendered template's permissions. File permissions are 884 given as octal of the Unix file permissions `rwxrwxrwx`. 885 886 - `RightDelim` - Specifies the right delimiter to use in the template. The default 887 is "}}" for some templates, it may be easier to use a different delimiter that 888 does not conflict with the output file itself. 889 890 - `SourcePath` - Specifies the path to the template to be rendered. `SourcePath` 891 is mutually exclusive with `EmbeddedTmpl` attribute. The source can be fetched 892 using an [`Artifact`](#artifact) resource. The template must exist on the 893 machine prior to starting the task; it is not possible to reference a template 894 inside of a Docker container, for example. 895 896 - `Splay` - Specifies a random amount of time to wait between 0 ms and the given 897 splay value before invoking the change mode. Should be specified in 898 nanoseconds. 899 900 - `VaultGrace` - Specifies the grace period between lease renewal and secret 901 re-acquisition. When renewing a secret, if the remaining lease is less than or 902 equal to the configured grace, the template will request a new credential. 903 This prevents Vault from revoking the secret at its expiration and the task 904 having a stale secret. If the grace is set to a value that is higher than your 905 default TTL or max TTL, the template will always read a new secret. If the 906 task defines several templates, the `vault_grace` will be set to the lowest 907 value across all the templates. 908 909 ```json 910 { 911 "Templates": [ 912 { 913 "SourcePath": "local/config.conf.tpl", 914 "DestPath": "local/config.conf", 915 "EmbeddedTmpl": "", 916 "ChangeMode": "signal", 917 "ChangeSignal": "SIGUSR1", 918 "Splay": 5000000000 919 } 920 ] 921 } 922 ``` 923 924 [ct]: https://github.com/hashicorp/consul-template "Consul Template by HashiCorp" 925 [drain]: /docs/commands/node/drain.html 926 [env]: /docs/runtime/environment.html "Nomad Runtime Environment"