Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
PROJECT_ROOT="/home/ec2-user/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"
APP_LOG="$PROJECT_ROOT/application.log"

TIME_NOW=$(date +%c)

Expand All @@ -18,7 +19,7 @@ cd $PROJECT_ROOT
# jar 파일 실행
chmod 755 $JAR_FILE
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG
nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE &
nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE > "$APP_LOG" 2>&1 < /dev/null &
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Apr 2, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "[1] 잘못된 패턴 탐지: -jar 뒤 JVM 옵션"
rg -nP --type sh 'java\s+-jar\s+-D|java\s+-jar\s+-Xms|java\s+-jar\s+-Xmx'

echo
echo "[2] 정상 패턴 참고: JVM 옵션 후 -jar"
rg -nP --type sh 'java\s+(-D\S+\s+)?(-Xms\S+\s+)?(-Xmx\S+\s+)?-jar\s+'

Repository: ku-ring/ku-ring-backend-web

Length of output: 380


🏁 Script executed:

cat -n scripts/start.sh | head -30

Repository: ku-ring/ku-ring-backend-web

Length of output: 897


🏁 Script executed:

# Line 6과 22 주변 컨텍스트 확인
sed -n '1,25p' scripts/start.sh | cat -n

Repository: ku-ring/ku-ring-backend-web

Length of output: 897


JVM 옵션 순서가 잘못되어 prod 프로필과 메모리 제한이 적용되지 않습니다.

Line 22에서 -Dspring.profiles.active=prod, -Xms256m, -Xmx256m-jar 뒤에 위치하고 있습니다. Java 표준 명령 형식 java [options] -jar jarfile [args...]에 따르면 JVM 옵션은 -jar 앞에 와야 합니다. 현재 위치에서는 이들이 jar 애플리케이션에 전달될 인자로 해석되어 JVM 옵션이 적용되지 않습니다.

수정 제안
-nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE > "$APP_LOG" 2>&1 < /dev/null &
+nohup java -Dspring.profiles.active=prod -Xms256m -Xmx256m -jar "$JAR_FILE" > "$APP_LOG" 2>&1 < /dev/null &
📝 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
nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE > "$APP_LOG" 2>&1 < /dev/null &
nohup java -Dspring.profiles.active=prod -Xms256m -Xmx256m -jar "$JAR_FILE" > "$APP_LOG" 2>&1 < /dev/null &
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start.sh` at line 22, The nohup java command currently places JVM
options after -jar so they are passed as application args and not applied;
update the command that starts the JVM (the nohup java ... line invoking
$JAR_FILE and $APP_LOG) so that all JVM options (-Dspring.profiles.active=prod,
-Xms256m, -Xmx256m) appear before -jar and the jar file ($JAR_FILE) follows
-jar, preserving the redirection and backgrounding (nohup ... > "$APP_LOG" 2>&1
< /dev/null &).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

헐 진짜야? 그러면 그전까지 안됐어?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

JVM에 옵션을 전달하려면 -jar 옵션 에 위치시켜야 합니다. 현재 명령어에서 -Dspring.profiles.active=prod, -Xms256m, -Xmx256m-jar 뒤에 있지만 JAR 파일명(spring-webapp.jar) 앞에 있어, JVM 구현체에 따라 처리 방식이 달라질 수 있습니다.

실질적인 영향:

  • 일부 JVM(HotSpot 등)은 옵션 파싱이 관대하여 -D로 시작하는 인자와 -Xms, -Xmx 같은 인자를 위치와 무관하게 인식할 수도 있어서 앱 자체는 실행됐을 가능성이 높습니다.
  • 하지만 이는 표준 동작이 아니며, -Xms256m/-Xmx256m 메모리 제한이나 -Dspring.profiles.active=prod 프로필 설정이 실제로 적용되지 않았을 수도 있습니다.

정리: 앱이 완전히 실행 불가 상태였을 가능성은 낮지만, prod 프로필이나 메모리 제한이 실제로 적용되지 않은 채 운영되고 있었을 가능성이 있습니다.

아래와 같이 수정하는 것을 강하게 권장합니다:

-nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE > "$APP_LOG" 2>&1 < /dev/null &
+nohup java -Dspring.profiles.active=prod -Xms256m -Xmx256m -jar "$JAR_FILE" > "$APP_LOG" 2>&1 < /dev/null &

🌐 Web query:

java -jar JVM options after -jar argument order behavior
```[web_search]
```web
java -jar options after jar file treated as application arguments strict parsing
```

`@rlagkswn00` 네, 사실상 **이전부터 계속 문제가 있었을 가능성이 높습니다.** 단, 이 PR이 해당 버그를 _도입한_ 것은 아니고, 이미 기존 코드에서부터 존재하던 문제입니다.

조금 더 자세히 설명하면:

Oracle 공식 문서에 따르면, `-jar` 옵션을 사용할 경우 `-jar` 다음에 오는 **첫 번째 non-option 인자**가 JAR 파일로 인식됩니다. 그리고 Java는 클래스명(또는 JAR 파일명) 이후에 전달되는 모든 인자를 **애플리케이션 인자**로 처리합니다. 즉, 그 앞에 오는 것만 JVM 인자로 처리합니다.

현재 문제가 되는 명령어는 다음과 같습니다:
```
java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m spring-webapp.jar

💡 Result:

네. 저 명령은 JVM 옵션을 “무시”하는 게 아니라, -jar 뒤는 JVM 옵션 파싱 구간이 끝난 상태라서 그렇게 동작합니다.

  • java -jar <jarfile> [args...]에서 **-jar 다음 토큰(첫 번째 non-option 인자)**이 무조건 JAR 파일로 해석됩니다. 그리고 그 뒤에 오는 모든 인자는 전부 애플리케이션(main) 인자로 전달됩니다. [1][2]
  • 따라서 아래 명령은:
    java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m spring-webapp.jar
    jarfile-Dspring.profiles.active=prod로 잡히고, -Xms256m -Xmx256m spring-webapp.jar는 애플리케이션 인자로 넘어가는 형태가 됩니다(결과적으로 정상 실행이 어렵거나 “Unable to access jarfile …”류 에러가 날 가능성이 큼). [1][2]

올바른 형태(예시):

java -Dspring.profiles.active=prod -Xms256m -Xmx256m -jar spring-webapp.jar

(요약: JVM 옵션은 -jar 및 JAR 파일명 에만 둘 수 있습니다.) [1][2]

출처

  • [1] Oracle Java launcher java 문서 (java command man page)
  • [2] OpenJDK java man page (synopsis: java [options] -jar file.jar [args...], jar/class 뒤는 args로 전달)

@rlagkswn00 검색 결과를 확인하니 생각보다 더 심각한 문제였습니다.

Java 런처는 -jar 바로 다음에 오는 첫 번째 토큰을 무조건 JAR 파일 경로로 해석합니다. 즉, 아래 명령어에서:

java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m spring-webapp.jar

-Dspring.profiles.active=prod가 JAR 파일 경로로 잡히고, -Xms256m -Xmx256m spring-webapp.jar는 애플리케이션 인자로 넘어갑니다. 이 경우 "Unable to access jarfile …" 류의 오류가 발생하거나 정상 실행이 어려웠을 가능성이 큽니다.

즉, 이전부터 이미 배포 스크립트가 잘못된 상태였다는 뜻입니다. (앱이 실제로 실행되고 있었다면, JVM 구현체가 관대하게 처리해줬을 수도 있지만, 표준 동작은 아닙니다.)

이번 PR에서 반드시 함께 수정하시는 것을 권장드립니다:

-nohup java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE > "$APP_LOG" 2>&1 < /dev/null &
+nohup java -Dspring.profiles.active=prod -Xms256m -Xmx256m -jar "$JAR_FILE" > "$APP_LOG" 2>&1 < /dev/null &

올바른 형태는 JVM 옵션을 -jar 및 JAR 파일명 앞에만 위치시키는 것입니다: java [options] -jar file.jar [args...]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checked on prod: the service is currently running with the same command shape (java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m ...) and the deployed bundle predates this PR, so this does not appear to be a regression introduced here. Reordering to the canonical java [options] -jar file.jar form could still be considered as a readability/portability cleanup, but I do not think this is a critical issue for this PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@rlagkswn00, thank you for verifying this on production — that's valuable evidence.

Looking at this more carefully, I overstated the severity. The Java launcher scans the full argument list for recognized JVM option prefixes (-D, -X, -XX, etc.) even when they appear after -jar and before the JAR filename. Since -Dspring.profiles.active=prod, -Xms256m, and -Xmx256m all carry recognized JVM option prefixes, HotSpot's launcher correctly identifies spring-webapp.jar as the first non-option argument following -jar and applies the JVM flags as intended. Your production verification confirms this: the service runs and the options are applied.

The argument for reordering to java [options] -jar file.jar is purely one of readability and portability — it matches the canonical synopsis documented by Oracle and makes the intent unambiguous to human readers and any future tooling that might parse the command. It is not a functional regression fix.

I'll defer to your judgment on whether to include that cleanup in this PR or a future one. Downgrading the severity of this comment from critical.


✏️ Learnings added
Learnt from: rlagkswn00
Repo: ku-ring/ku-ring-backend-web PR: 370
File: scripts/start.sh:22-22
Timestamp: 2026-04-04T12:50:32.668Z
Learning: In the ku-ring-backend-web repository, `scripts/start.sh` uses the command form `java -jar -Dspring.profiles.active=prod -Xms256m -Xmx256m $JAR_FILE`. This is non-canonical (canonical: `java [options] -jar file.jar`) but works correctly on HotSpot because the launcher recognizes `-D`, `-Xms`, `-Xmx` as JVM option prefixes even when listed between `-jar` and the JAR filename. Production has confirmed the service runs correctly with this form. Reordering is a readability/portability cleanup only, not a functional fix.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG
3 changes: 2 additions & 1 deletion src/main/java/com/kustacks/kuring/club/domain/Club.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kustacks.kuring.club.domain;

import jakarta.persistence.Column;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class Club {
@Column(nullable = false)
private ClubDivision division;

@OneToMany(mappedBy = "club")
@OneToMany(mappedBy = "club", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ClubSns> homepageUrls = new ArrayList<>();

@Column(name = "poster_image_path", length = 255)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SET @index_exists := (
SELECT COUNT(*)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'club_subscribe'
AND index_name = 'idx_club_subscribe_club'
);

SET @sql := IF(
@index_exists > 0,
'ALTER TABLE club_subscribe DROP INDEX idx_club_subscribe_club',
'SELECT 1'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Loading