Skip to content

Commit

Permalink
Update stop.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ibaesuyeon authored Aug 21, 2024
1 parent 95c4292 commit d20047c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
#!/usr/bin/env bash

PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"

JAR_FILE="spring-webapp.jar"
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# ν˜„μž¬ ꡬ동 쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ pid 확인
CURRENT_PID=$(pgrep -f $JAR_FILE)
# ν˜„μž¬ ꡬ동 쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ PID 확인
CURRENT_PID=$(pgrep -f "java -jar $PROJECT_ROOT/$JAR_FILE")

# ν”„λ‘œμ„ΈμŠ€κ°€ 켜져 있으면 μ’…λ£Œ
if [ -z $CURRENT_PID ]; then
if [ -z "$CURRENT_PID" ]; then
echo "$TIME_NOW > ν˜„μž¬ 싀행쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μ—†μŠ΅λ‹ˆλ‹€" >> $DEPLOY_LOG
else
echo "$TIME_NOW > 싀행쀑인 $CURRENT_PID μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ’…λ£Œ" >> $DEPLOY_LOG
kill -15 $CURRENT_PID
sleep 10 # μ’…λ£Œ ν›„ μž μ‹œ κΈ°λ‹€λ € ν¬νŠΈκ°€ ν•΄μ œλ˜λ„λ‘ 함

# μ’…λ£Œ ν›„ μž μ‹œ 기닀리기
sleep 10

# ν”„λ‘œμ„ΈμŠ€κ°€ 아직 μ’…λ£Œλ˜μ§€ μ•Šμ•˜μ„ 경우 κ°•μ œ μ’…λ£Œ
CURRENT_PID=$(pgrep -f "java -jar $PROJECT_ROOT/$JAR_FILE")
if [ ! -z "$CURRENT_PID" ]; then
echo "$TIME_NOW > κ°•μ œ μ’…λ£Œ ν”„λ‘œμ„ΈμŠ€ $CURRENT_PID" >> $DEPLOY_LOG
kill -9 $CURRENT_PID
fi
fi

# ν¬νŠΈκ°€ ν•΄μ œλ  λ•ŒκΉŒμ§€ 확인
for i in {1..10}; do
if ! lsof -i :8080 > /dev/null 2>&1; then
echo "$TIME_NOW > 포트 8080이 ν•΄μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€." >> $DEPLOY_LOG
break
fi
echo "$TIME_NOW > 포트 8080이 아직 μ‚¬μš© μ€‘μž…λ‹ˆλ‹€. $i 번째 λŒ€κΈ°..." >> $DEPLOY_LOG
sleep 1
done

0 comments on commit d20047c

Please sign in to comment.