Skip to content

Commit 6db3dc2

Browse files
authored
hotfix: db ec2에 OOM 방지를 위한 swap 메모리 추가 (#59)
1 parent 8bba772 commit 6db3dc2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

modules/app_stack/scripts/mysql_setup.sh.tftpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,32 @@ command -v docker >/dev/null
1818
command -v blkid >/dev/null
1919
command -v mkfs.ext4 >/dev/null
2020
command -v mountpoint >/dev/null
21+
command -v swapon >/dev/null
22+
command -v mkswap >/dev/null
23+
24+
ensure_swap() {
25+
local swap_file="/swapfile"
26+
27+
if ! swapon --show=NAME --noheadings | grep -Fxq "$swap_file"; then
28+
if [ ! -f "$swap_file" ]; then
29+
fallocate -l 2G "$swap_file" || dd if=/dev/zero of="$swap_file" bs=1M count=2048
30+
fi
31+
32+
chmod 600 "$swap_file"
33+
if [ "$(blkid -s TYPE -o value "$swap_file" 2>/dev/null || true)" != "swap" ]; then
34+
mkswap "$swap_file"
35+
fi
36+
37+
swapon "$swap_file"
38+
fi
39+
40+
if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then
41+
printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab
42+
fi
43+
}
2144

2245
systemctl enable docker
46+
ensure_swap
2347

2448
DATA_VOLUME_ID="${db_data_volume_id}"
2549
DATA_VOLUME_SERIAL="$(printf '%s' "$DATA_VOLUME_ID" | tr -d '-')"

0 commit comments

Comments
 (0)