From 7d2feba0bd1ab9b72108f2a45ed170e263a26f39 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Mon, 16 Dec 2024 15:28:30 -0800 Subject: [PATCH] Fix a bug when swapfile doesn't exist (#6068) I made a mistake in https://github.com/pytorch/test-infra/pull/6066 and should have checked if the file exists first. --- .../modules/runners-instances/templates/user-data.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/terraform-aws-github-runner/modules/runners-instances/templates/user-data.sh b/terraform-aws-github-runner/modules/runners-instances/templates/user-data.sh index 0716f89ac9..d4b4db6b05 100644 --- a/terraform-aws-github-runner/modules/runners-instances/templates/user-data.sh +++ b/terraform-aws-github-runner/modules/runners-instances/templates/user-data.sh @@ -138,9 +138,11 @@ fi ${post_install} -# Cleanup any existing swapfile just to be sure -sudo swapoff /swapfile -sudo rm /swapfile +if [[ -f /swapfile ]]; then + # Cleanup any existing swapfile just to be sure + sudo swapoff /swapfile + sudo rm /swapfile +fi # before allocating a new one sudo fallocate -l 3G /swapfile sudo chmod 600 /swapfile