From 95c577aadfe0bac31f9921de27ea64bbd048df28 Mon Sep 17 00:00:00 2001 From: hariharan Date: Thu, 4 Jan 2024 19:24:48 +0530 Subject: [PATCH 1/4] Increase file limit. Fixes #12 --- modules/nomad-clients/scripts/setup_client.tftpl.sh | 9 +++++++++ modules/nomad-servers/scripts/setup_server.tftpl.sh | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/nomad-clients/scripts/setup_client.tftpl.sh b/modules/nomad-clients/scripts/setup_client.tftpl.sh index 7c041d4..ff9121a 100644 --- a/modules/nomad-clients/scripts/setup_client.tftpl.sh +++ b/modules/nomad-clients/scripts/setup_client.tftpl.sh @@ -87,8 +87,14 @@ search ap-south-1.compute.internal EOF } +# Increase the file limit +modify_nomad_systemd_config() { + sudo sed -i 's/LimitNOFILE=65536/LimitNOFILE=900000/' /lib/systemd/system/nomad.service +} + # Enables nomad systemd service start_nomad() { + sudo systemctl daemon-reload sudo systemctl enable --now nomad } @@ -197,6 +203,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-servers/scripts/setup_server.tftpl.sh b/modules/nomad-servers/scripts/setup_server.tftpl.sh index 84619ef..c522fa5 100644 --- a/modules/nomad-servers/scripts/setup_server.tftpl.sh +++ b/modules/nomad-servers/scripts/setup_server.tftpl.sh @@ -81,8 +81,14 @@ set_hostname() { done } +# Increase the file limit +modify_nomad_systemd_config() { + sudo sed -i 's/LimitNOFILE=65536/LimitNOFILE=900000/' /lib/systemd/system/nomad.service +} + # Enables nomad systemd service start_nomad() { + sudo systemctl daemon-reload sudo systemctl enable --now nomad } @@ -149,6 +155,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 From f701bada9076b87fc2a0bc38bfac00db093f56fa Mon Sep 17 00:00:00 2001 From: hariharan Date: Fri, 5 Jan 2024 10:16:14 +0530 Subject: [PATCH 2/4] Use variable to define nomad file limit --- modules/nomad-clients/ec2.tf | 1 + modules/nomad-clients/scripts/setup_client.tftpl.sh | 4 +++- modules/nomad-clients/variables.tf | 6 ++++++ modules/nomad-servers/launch_template.tf | 1 + modules/nomad-servers/scripts/setup_server.tftpl.sh | 4 +++- modules/nomad-servers/variables.tf | 6 ++++++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/nomad-clients/ec2.tf b/modules/nomad-clients/ec2.tf index 62de02e..a4afce5 100644 --- a/modules/nomad-clients/ec2.tf +++ b/modules/nomad-clients/ec2.tf @@ -37,6 +37,7 @@ resource "aws_instance" "nomad_client" { nomad_dc = var.cluster_name nomad_acl_enable = var.nomad_acl_enable }) + nomad_file_limit = var.nomad_file_limit })) tags = { diff --git a/modules/nomad-clients/scripts/setup_client.tftpl.sh b/modules/nomad-clients/scripts/setup_client.tftpl.sh index ff9121a..cc088e1 100644 --- a/modules/nomad-clients/scripts/setup_client.tftpl.sh +++ b/modules/nomad-clients/scripts/setup_client.tftpl.sh @@ -89,7 +89,9 @@ EOF # Increase the file limit modify_nomad_systemd_config() { - sudo sed -i 's/LimitNOFILE=65536/LimitNOFILE=900000/' /lib/systemd/system/nomad.service + if [ ${nomad_file_limit} > 65536 ]; then + sudo sed -i '/^LimitNOFILE/s/=.*$/=${nomad_file_limit}/' /lib/systemd/system/nomad.service + fi } # Enables nomad systemd service 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..7ce6d06 100644 --- a/modules/nomad-servers/launch_template.tf +++ b/modules/nomad-servers/launch_template.tf @@ -20,6 +20,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 c522fa5..9895ba7 100644 --- a/modules/nomad-servers/scripts/setup_server.tftpl.sh +++ b/modules/nomad-servers/scripts/setup_server.tftpl.sh @@ -83,7 +83,9 @@ set_hostname() { # Increase the file limit modify_nomad_systemd_config() { - sudo sed -i 's/LimitNOFILE=65536/LimitNOFILE=900000/' /lib/systemd/system/nomad.service + if [ ${nomad_file_limit} > 65536 ]; then + sudo sed -i '/^LimitNOFILE/s/=.*$/=${nomad_file_limit}/' /lib/systemd/system/nomad.service + fi } # Enables nomad systemd service 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 +} From 1341d1dadce1a721f509a3c283003fd112f17368 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Fri, 5 Jan 2024 11:04:18 +0530 Subject: [PATCH 3/4] feat: add missing ulimit var ref to map --- modules/nomad-clients/ec2.tf | 1 + modules/nomad-clients/launch_template.tf | 1 + modules/nomad-servers/launch_template.tf | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/nomad-clients/ec2.tf b/modules/nomad-clients/ec2.tf index a4afce5..9788354 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-servers/launch_template.tf b/modules/nomad-servers/launch_template.tf index 7ce6d06..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 From db3a5945b684b96bd51d7e49a2871873f214b820 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Fri, 5 Jan 2024 11:15:43 +0530 Subject: [PATCH 4/4] chore: remove duplicate entry for file_limit var --- modules/nomad-clients/ec2.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/nomad-clients/ec2.tf b/modules/nomad-clients/ec2.tf index 9788354..c968205 100644 --- a/modules/nomad-clients/ec2.tf +++ b/modules/nomad-clients/ec2.tf @@ -38,7 +38,6 @@ resource "aws_instance" "nomad_client" { nomad_dc = var.cluster_name nomad_acl_enable = var.nomad_acl_enable }) - nomad_file_limit = var.nomad_file_limit })) tags = {