github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/website/source/docs/jobspec/environment.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Runtime Environment" 4 sidebar_current: "docs-jobspec-environment" 5 description: |- 6 Learn how to configure the Nomad runtime environment. 7 --- 8 9 # Runtime Environment 10 11 Some settings you specify in your [job specification](/docs/jobspec/) are passed to tasks 12 when they start. Other settings are dynamically allocated when your job is 13 scheduled. Both types of values are made available to your job through 14 environment variables. 15 16 ## Summary 17 18 <table class="table table-bordered table-striped"> 19 <tr> 20 <th>Variable</th> 21 <th>Description</th> 22 </tr> 23 <tr> 24 <td>NOMAD_ALLOC_DIR</td> 25 <td>Path to the shared alloc directory</td> 26 </tr> 27 <tr> 28 <td>NOMAD_TASK_DIR</td> 29 <td>Path to the local task directory</td> 30 </tr> 31 <tr> 32 <td>NOMAD_MEMORY_LIMIT</td> 33 <td>The task's memory limit in MB</td> 34 </tr> 35 <tr> 36 <td>NOMAD_CPU_LIMIT</td> 37 <td>The task's CPU limit in MHz</td> 38 </tr> 39 <tr> 40 <td>NOMAD_ALLOC_ID</td> 41 <td>The allocation ID of the task</td> 42 </tr> 43 <tr> 44 <td>NOMAD_ALLOC_NAME</td> 45 <td>The allocation name of the task</td> 46 </tr> 47 <tr> 48 <td>NOMAD_ALLOC_INDEX</td> 49 <td>The allocation index; useful to distinguish instances of task groups</td> 50 </tr> 51 <tr> 52 <td>NOMAD_TASK_NAME</td> 53 <td>The task's name</td> 54 </tr> 55 <tr> 56 <td>NOMAD_IP_"label"</td> 57 <td>The IP of the the port with the given label</td> 58 </tr> 59 <tr> 60 <td>NOMAD_PORT_"label"</td> 61 <td>The port value with the given label</td> 62 </tr> 63 <tr> 64 <td>NOMAD_ADDR_"label"</td> 65 <td>The IP:Port pair of the the port with the given label</td> 66 </tr> 67 <tr> 68 <td>NOMAD_HOST_PORT_"label"</td> 69 <td>The host port for the given label if the port is port mapped</td> 70 </tr> 71 <tr> 72 <td>NOMAD_META_"key"</td> 73 <td>The metadata of the task</td> 74 </tr> 75 </table> 76 77 ## Task Identifiers 78 79 Nomad will pass both the allocation ID and name as well as the task's name. 80 These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`, `NOMAD_ALLOC_INDEX` and 81 `NOMAD_TASK_NAME`. The allocation ID and index can be useful when the task being 82 run needs a unique identifier or to know its instance count. 83 84 ## Resources 85 86 When you request resources for a job, Nomad creates a resource offer. The final 87 resources for your job are not determined until it is scheduled. Nomad will 88 tell you which resources have been allocated after evaluation and placement. 89 90 ### CPU and Memory 91 92 Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and 93 `NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to 94 fit inside the resource allocation that nomad provides. For example, you can use 95 the memory limit to inform how large your in-process cache should be, or to 96 decide when to flush buffers to disk. 97 98 Both CPU and memory are presented as integers. The unit for CPU limit is 99 `1024 = 1Ghz`. The unit for memory is `1 = 1 megabytes`. 100 101 Writing your applications to adjust to these values at runtime provides greater 102 scheduling flexibility since you can adjust the resource allocations in your 103 job specification without needing to change your code. You can also schedule workloads 104 that accept dynamic resource allocations so they can scale down/up as your 105 cluster gets more or less busy. 106 107 ### Networking 108 109 Nomad assigns IPs and ports to your jobs and exposes them via environment 110 variables. See the [Networking](/docs/jobspec/networking.html) page for more 111 details. 112 113 ### Task Directories <a id="task_dir"></a> 114 115 Nomad makes the following two directories available to tasks: 116 117 * `alloc/`: This directory is shared across all tasks in a task group and can be 118 used to store data that needs to be used by multiple tasks, such as a log 119 shipper. 120 * `local/`: This directory is private to each task. It can be used to store 121 arbitrary data that shouldn't be shared by tasks in the task group. 122 123 Both these directories are persisted until the allocation is removed, which 124 occurs hours after all the tasks in the task group enter terminal states. This 125 gives time to view the data produced by tasks. 126 127 Depending on the driver and operating system being targeted, the directories are 128 made available in various ways. For example, on `docker` the directories are 129 binded to the container, while on `exec` on Linux the directories are mounted into the 130 chroot. Regardless of how the directories are made available, the path to the 131 directories can be read through the following environment variables: 132 `NOMAD_ALLOC_DIR` and `NOMAD_TASK_DIR`. 133 134 ## Meta 135 136 The job specification also allows you to specify a `meta` block to supply arbitrary 137 configuration to a task. This allows you to easily provide job-specific 138 configuration even if you use the same executable unit in multiple jobs. These 139 key-value pairs are passed through to the job as `NOMAD_META_"key"={value}`, 140 where `key` is UPPERCASED from the job specification. 141 142 Currently there is no enforcement that the meta values be lowercase, but using 143 multiple keys with the same uppercased representation will lead to undefined 144 behavior.