Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions modules/app_stack/scripts/mysql_setup.sh.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +40 to +41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

fstab 중복 등록 버그 — regex가 의도한 대로 매칭되지 않습니다.

[^#]/swapfile의 첫 글자 /를 소비한 뒤, 패턴의 리터럴 /swapfile는 잔여 텍스트 swapfile ...와 매칭을 시도하므로 항상 실패합니다. 결과적으로 swap이 이미 활성화된 상태에서도(라인 27 가드 바깥에 있음) 매 실행 시마다 /etc/fstab에 중복 엔트리가 추가됩니다.

🐛 Proposed fix
-  if ! grep -Eq "^[^#][[:space:]]*$swap_file[[:space:]]+none[[:space:]]+swap[[:space:]]" /etc/fstab; then
+  if ! grep -Eq "^[[:space:]]*${swap_file}[[:space:]]+none[[:space:]]+swap" /etc/fstab; then
     printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab
   fi

/swapfile/로 시작하므로 # 주석 라인과 자연히 구분되며, ^[[:space:]]*로 선행 공백도 허용합니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
if ! grep -Eq "^[[:space:]]*${swap_file}[[:space:]]+none[[:space:]]+swap" /etc/fstab; then
printf '%s none swap sw 0 0\n' "$swap_file" >> /etc/fstab
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/app_stack/scripts/mysql_setup.sh.tftpl` around lines 40 - 41, In the
fstab guard, the regex in the swap-entry check incorrectly consumes the first
character of the swap path, so duplicate entries are appended. Update the grep
pattern used by the fstab registration block to match optional leading
whitespace followed by the full $swap_file path, while still excluding commented
lines and matching the existing none/swap fields.

fi
}

systemctl enable docker
ensure_swap

DATA_VOLUME_ID="${db_data_volume_id}"
DATA_VOLUME_SERIAL="$(printf '%s' "$DATA_VOLUME_ID" | tr -d '-')"
Expand Down
Loading