@@ -165,6 +165,34 @@ bootstrap_acl() {
165
165
fi
166
166
}
167
167
168
+ enable_mem_oversubscription () {
169
+ command -v jq > /dev/null 2>&1 || { log " ERROR" " jq not found in PATH. Aborting." ; exit 1; }
170
+
171
+ local nomad_config
172
+ nomad_config=$( curl -s http://0.0.0.0:4646/v1/operator/scheduler/configuration %{ if " ${nomad_acl_bootstrap_token} " ! = " " }-H " X-Nomad-Token: ${nomad_acl_bootstrap_token} " %{ endif })
173
+ if [[ " $nomad_config " == * " Permission denied" * ]]; then
174
+ log " ERROR" " Permission denied while enabling memory oversubscription. Please check the bootstrap token."
175
+ else
176
+ log " INFO" " Checking if Memory Over subscription is already enabled."
177
+ mem_oversub_enabled=$( echo " $nomad_config " | jq ' .SchedulerConfig | .MemoryOversubscriptionEnabled' )
178
+ if [ " $mem_oversub_enabled " == " false" ]; then
179
+ log " INFO" " Memory Oversubscription is disabled. Enabling."
180
+ echo " $nomad_config " | \
181
+ status_code=(jq ' .SchedulerConfig | .MemoryOversubscriptionEnabled=true' | \
182
+ curl -s -X PUT --write-out %%{http_code} \
183
+ %{ if " ${nomad_acl_bootstrap_token} " ! = " " }-H " X-Nomad-Token: ${nomad_acl_bootstrap_token} " %{ endif } \
184
+ http://0.0.0.0:4646/v1/operator/scheduler/configuration -d @-)
185
+ if [ " $status_code " == " 200" ]; then
186
+ log " INFO" " Successfully enabled Memory Oversubscription!"
187
+ else
188
+ log " ERROR" " Something went wrong while updating memory oversubscription. Please run it manually."
189
+ fi
190
+ else
191
+ log " INFO" " Memory Oversubscription is already enabled!"
192
+ fi
193
+ fi
194
+ }
195
+
168
196
log " INFO" " Fetching EC2 Tags from AWS"
169
197
store_tags
170
198
@@ -195,4 +223,9 @@ log "INFO" "Skipping ACL Bootstrap for Nomad as 'nomad_acl_enable' is not set to
195
223
log " INFO" " Restarting services"
196
224
restart_nomad
197
225
226
+ %{ if enable_memory_oversubscription }
227
+ log " INFO" " Enabling Memory Oversubscription for the cluster"
228
+ enable_mem_oversubscription
229
+ %{ endif }
230
+
198
231
log " INFO" " Finished server initializing process! Enjoy Nomad!"
0 commit comments