From 68dd7713962c42084380eff1971af55943792c39 Mon Sep 17 00:00:00 2001 From: Hexeong <123macanic@naver.com> Date: Fri, 10 Jul 2026 13:26:06 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20db=20ec2=EC=97=90=20OOM=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=9C=84=ED=95=9C=20swap=20=EB=A9=94?= =?UTF-8?q?=EB=AA=A8=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app_stack/scripts/mysql_setup.sh.tftpl | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/app_stack/scripts/mysql_setup.sh.tftpl b/modules/app_stack/scripts/mysql_setup.sh.tftpl index 1904877..75ae358 100644 --- a/modules/app_stack/scripts/mysql_setup.sh.tftpl +++ b/modules/app_stack/scripts/mysql_setup.sh.tftpl @@ -18,8 +18,32 @@ command -v docker >/dev/null command -v blkid >/dev/null command -v mkfs.ext4 >/dev/null command -v mountpoint >/dev/null +command -v swapon >/dev/null +command -v mkswap >/dev/null + +ensure_swap() { + local swap_file="/swapfile" + + if ! swapon --show=NAME --noheadings | grep -Fxq "$swap_file"; then + if [ ! -f "$swap_file" ]; then + fallocate -l 2G "$swap_file" || dd if=/dev/zero of="$swap_file" bs=1M count=2048 + fi + + chmod 600 "$swap_file" + if [ "$(blkid -s TYPE -o value "$swap_file" 2>/dev/null || true)" != "swap" ]; then + mkswap "$swap_file" + fi + + swapon "$swap_file" + fi + + if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then + printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab + fi +} systemctl enable docker +ensure_swap DATA_VOLUME_ID="${db_data_volume_id}" DATA_VOLUME_SERIAL="$(printf '%s' "$DATA_VOLUME_ID" | tr -d '-')"