Skip to content

fix: AfterInstall hook에서 ELK+Filebeat 실행하도록 수정#197

Merged
lsh2613 merged 1 commit intodevfrom
fix/#194-3
Jul 11, 2025
Merged

fix: AfterInstall hook에서 ELK+Filebeat 실행하도록 수정#197
lsh2613 merged 1 commit intodevfrom
fix/#194-3

Conversation

@lsh2613
Copy link
Contributor

@lsh2613 lsh2613 commented Jul 11, 2025

⭐ Summary

#194


📌 Tasks

  1. AfterInstall hook에서 docker-compose를 실행하도록 수정

@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

📝 Walkthrough

Walkthrough

appspec.yml에서 BeforeInstall 훅과 scripts/pre_install.sh 스크립트가 완전히 제거되었습니다. 대신, scripts/start.sh에 컨테이너 상태 점검 및 필요시 ELK/Filebeat 재시작 로직이 추가되어, 기존의 사전 설치 단계 로직이 배포 시작 시점으로 이동되었습니다.

Changes

파일/경로 변경 요약
appspec.yml BeforeInstall 훅 및 scripts/pre_install.sh 실행 부분 삭제
scripts/pre_install.sh ELK 및 Filebeat 컨테이너 상태 점검 및 재시작 스크립트 전체 삭제
scripts/start.sh 컨테이너 상태 점검 및 필요시 재시작 로직 추가. 기존 jar 복사 및 Java 실행 전 단계에 삽입

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant start.sh
    participant Docker
    participant docker-compose

    User->>start.sh: 스크립트 실행
    start.sh->>Docker: pitchain_* 컨테이너 상태 확인(docker ps)
    alt 컨테이너 중단됨
        start.sh->>docker-compose: ELK/Filebeat 재시작(docker-compose up --build -d)
    else 모두 실행 중
        start.sh->>User: "모든 컨테이너가 정상적으로 실행 중입니다."
    end
    start.sh->>start.sh: jar 복사 및 Java 앱 실행(이전과 동일)
Loading

Possibly related PRs

  • fix/#194-2 #196: pre_install.sh 스크립트의 docker-compose 명령에 env 파일 옵션을 추가하는 변경으로, 본 PR의 스크립트 삭제와 직접적으로 연관됨(수정 vs. 삭제).
  • refactor: app 실행 전 ELK+Filebeat 실행 #193: ELK 및 Filebeat 컨테이너 상태 점검 및 재시작 로직을 추가했던 PR로, 본 PR에서 해당 로직이 제거 및 이동됨(추가 vs. 삭제/이동).

Suggested reviewers

  • jeongmallro
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lsh2613 lsh2613 merged commit ff5afc8 into dev Jul 11, 2025
1 of 2 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
scripts/start.sh (3)

5-11: 컨테이너 실행 여부만으로는 건강 상태를 판단하기 부족합니다

docker ps로는 실행(process) 상태만 확인할 뿐, Healthcheck unhealthy 상태는 감지하지 못합니다.
추가로 컨테이너 이름이 공백·특수문자를 포함할 가능성은 낮지만, grep -q "^${CONTAINER}$" 대신 --filter name=... 사용이 안전합니다.

예시:

for CONTAINER in pitchain_filebeat pitchain_logstash pitchain_kibana pitchain_elasticsearch; do
  STATUS=$(docker inspect -f '{{.State.Health.Status}}' "$CONTAINER" 2>/dev/null || echo "not_found")
  if [[ "$STATUS" != "healthy" ]]; then
    echo "$CONTAINER 상태: $STATUS"
    NEED_RESTART=1
  fi
done

13-18: NEED_RESTART 비교 시 따옴표를 사용해 빈 값 오동작 방지

변수가 비어 있을 때 [ $NEED_RESTART -eq 1 ] 는 “단항 연산자 기대” 오류를 유발합니다. 아래처럼 인용해 주세요.

-if [ $NEED_RESTART -eq 1 ]; then
+if [ "$NEED_RESTART" -eq 1 ]; then

28-34: 경로에 공백 대비 및 빌드 산출물 검증 로직 추가 제안

  1. 변수·글로브를 인용하여 공백·메타문자 안전성 확보.
  2. *.jar 매칭 결과가 0개/2개 이상일 때의 처리 부재.
-cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE
-nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &
+BUILD_JAR=$(ls "$PROJECT_ROOT"/build/libs/*.jar 2>/dev/null | head -n1)
+if [[ -z "$BUILD_JAR" ]]; then
+  echo "ERROR: 빌드 산출물이 존재하지 않습니다." >> "$DEPLOY_LOG"
+  exit 1
+fi
+cp "$BUILD_JAR" "$JAR_FILE"
+nohup java -jar "$JAR_FILE" > "$APP_LOG" 2> "$ERROR_LOG" &
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef6f190 and 6b1c108.

📒 Files selected for processing (3)
  • appspec.yml (0 hunks)
  • scripts/pre_install.sh (0 hunks)
  • scripts/start.sh (1 hunks)
💤 Files with no reviewable changes (2)
  • appspec.yml
  • scripts/pre_install.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: CI

Comment on lines 1 to +4
#!/usr/bin/env bash

PROJECT_ROOT="/home/ec2-user/app"

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

set -euo pipefail 옵션으로 스크립트 안정성을 높이세요

에러 발생 시 즉시 종료(-e), 미정의 변수 사용 시 실패(-u), 파이프라인 오류 감지(-o pipefail)를 설정하지 않으면, cp·docker-compose 등의 실패가 그대로 넘어가서 배포가 불안정해질 수 있습니다. #!/usr/bin/env bash 바로 아래에 다음을 추가하는 것을 권장합니다.

 #!/usr/bin/env bash
+set -euo pipefail
📝 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
#!/usr/bin/env bash
PROJECT_ROOT="/home/ec2-user/app"
#!/usr/bin/env bash
set -euo pipefail
PROJECT_ROOT="/home/ec2-user/app"
🤖 Prompt for AI Agents
In scripts/start.sh at the beginning of the file (lines 1 to 4), the script
lacks the 'set -euo pipefail' option which ensures the script exits immediately
on errors, treats unset variables as errors, and detects errors in pipelines. To
fix this, add 'set -euo pipefail' immediately after the shebang line
'#!/usr/bin/env bash' to improve script reliability and error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant