diff --git a/modules/nomad-clients/ec2.tf b/modules/nomad-clients/ec2.tf index 62de02e..c968205 100644 --- a/modules/nomad-clients/ec2.tf +++ b/modules/nomad-clients/ec2.tf @@ -33,6 +33,7 @@ resource "aws_instance" "nomad_client" { enable_docker_plugin = var.enable_docker_plugin nomad_join_tag_key = "nomad_ec2_join" nomad_join_tag_value = var.nomad_join_tag_value + nomad_file_limit = var.nomad_file_limit nomad_client_cfg = templatefile("${path.module}/templates/nomad.tftpl", { nomad_dc = var.cluster_name nomad_acl_enable = var.nomad_acl_enable diff --git a/modules/nomad-clients/launch_template.tf b/modules/nomad-clients/launch_template.tf index 1db3958..04b0834 100644 --- a/modules/nomad-clients/launch_template.tf +++ b/modules/nomad-clients/launch_template.tf @@ -14,6 +14,7 @@ resource "aws_launch_template" "nomad_client" { enable_docker_plugin = var.enable_docker_plugin nomad_join_tag_key = "nomad_ec2_join" nomad_join_tag_value = var.nomad_join_tag_value + nomad_file_limit = var.nomad_file_limit nomad_client_cfg = templatefile("${path.module}/templates/nomad.tftpl", { nomad_dc = var.cluster_name nomad_acl_enable = var.nomad_acl_enable diff --git a/modules/nomad-clients/scripts/setup_client.tftpl.sh b/modules/nomad-clients/scripts/setup_client.tftpl.sh index 7c041d4..cc088e1 100644 --- a/modules/nomad-clients/scripts/setup_client.tftpl.sh +++ b/modules/nomad-clients/scripts/setup_client.tftpl.sh @@ -87,8 +87,16 @@ search ap-south-1.compute.internal EOF } +# Increase the file limit +modify_nomad_systemd_config() { + if [ ${nomad_file_limit} > 65536 ]; then + sudo sed -i '/^LimitNOFILE/s/=.*$/=${nomad_file_limit}/' /lib/systemd/system/nomad.service + fi +} + # Enables nomad systemd service start_nomad() { + sudo systemctl daemon-reload sudo systemctl enable --now nomad } @@ -197,6 +205,9 @@ log "INFO" "Adding docker config to Nomad" add_docker_to_nomad %{ endif } +log "INFO" "Modify Nomad systemd config" +modify_nomad_systemd_config + log "INFO" "Starting Nomad service" start_nomad diff --git a/modules/nomad-clients/variables.tf b/modules/nomad-clients/variables.tf index 2a34c8e..4b7eb7c 100644 --- a/modules/nomad-clients/variables.tf +++ b/modules/nomad-clients/variables.tf @@ -198,3 +198,9 @@ variable "nomad_acl_enable" { type = bool default = true } + +variable "nomad_file_limit" { + description = "Value for LimitNOFILE in nomad systemd config" + type = number + default = 900000 +} \ No newline at end of file diff --git a/modules/nomad-servers/launch_template.tf b/modules/nomad-servers/launch_template.tf index e1c2498..f0fa5e9 100644 --- a/modules/nomad-servers/launch_template.tf +++ b/modules/nomad-servers/launch_template.tf @@ -11,6 +11,7 @@ resource "aws_launch_template" "nomad_server" { user_data = base64encode(templatefile("${path.module}/scripts/setup_server.tftpl.sh", { nomad_acl_bootstrap_token = var.nomad_acl_bootstrap_token nomad_acl_enable = var.nomad_acl_enable + nomad_file_limit = var.nomad_file_limit nomad_server_cfg = templatefile("${path.module}/templates/nomad.tftpl", { nomad_dc = var.cluster_name aws_region = var.aws_region @@ -20,6 +21,7 @@ resource "aws_launch_template" "nomad_server" { nomad_join_tag_value = var.nomad_join_tag_value nomad_acl_enable = var.nomad_acl_enable }) + nomad_file_limit = var.nomad_file_limit })) metadata_options { diff --git a/modules/nomad-servers/scripts/setup_server.tftpl.sh b/modules/nomad-servers/scripts/setup_server.tftpl.sh index 84619ef..9895ba7 100644 --- a/modules/nomad-servers/scripts/setup_server.tftpl.sh +++ b/modules/nomad-servers/scripts/setup_server.tftpl.sh @@ -81,8 +81,16 @@ set_hostname() { done } +# Increase the file limit +modify_nomad_systemd_config() { + if [ ${nomad_file_limit} > 65536 ]; then + sudo sed -i '/^LimitNOFILE/s/=.*$/=${nomad_file_limit}/' /lib/systemd/system/nomad.service + fi +} + # Enables nomad systemd service start_nomad() { + sudo systemctl daemon-reload sudo systemctl enable --now nomad } @@ -149,6 +157,9 @@ set_hostname log "INFO" "Rendering server config for nomad" prepare_nomad_server_config +log "INFO" "Modify Nomad systemd config" +modify_nomad_systemd_config + log "INFO" "Starting Nomad service" start_nomad diff --git a/modules/nomad-servers/variables.tf b/modules/nomad-servers/variables.tf index 25a7aa1..d3ba871 100644 --- a/modules/nomad-servers/variables.tf +++ b/modules/nomad-servers/variables.tf @@ -168,3 +168,9 @@ variable "vpc" { type = string nullable = false } + +variable "nomad_file_limit" { + description = "Value for LimitNOFILE in nomad systemd config" + type = number + default = 900000 +}