Skip to content

Commit

Permalink
update start.sh
Browse files Browse the repository at this point in the history
애플리케이션 실행시 이전프로세스 확인 및 실행확인 로직 추가
  • Loading branch information
youngreal authored Nov 1, 2024
1 parent 6a02673 commit 32f88df
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
PROJECT_ROOT="/home/ec2-user/mapddang-back"
JAR_FILE="$PROJECT_ROOT/dnd-travel.jar"

APP_LOG="$PROJECT_ROOT/application.log"
ERROR_LOG="$PROJECT_ROOT/error.log"
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# 이전 프로세스 확인
CURRENT_PID=$(ps -ef | grep java | grep "$JAR_FILE" | grep -v grep | awk '{print $2}')
if [ -n "$CURRENT_PID" ]; then
echo "$TIME_NOW > 이전 프로세스($CURRENT_PID) 종료 시도" >> $DEPLOY_LOG
kill -9 $CURRENT_PID
fi

# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/dnd-travel-0.0.1-SNAPSHOT.jar $JAR_FILE
Expand All @@ -15,5 +20,7 @@ cp $PROJECT_ROOT/build/libs/dnd-travel-0.0.1-SNAPSHOT.jar $JAR_FILE
echo "$TIME_NOW > $JAR_FILE 실행" >> $DEPLOY_LOG
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &

CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 서비스 PID: $CURRENT_PID " >> $DEPLOY_LOG
# 실행 확인
sleep 3
NEW_PID=$(ps -ef | grep java | grep "$JAR_FILE" | grep -v grep | awk '{print $2}')
echo "$TIME_NOW > 새로운 애플리케이션 시작 (PID: $NEW_PID)" >> $DEPLOY_LOG

0 comments on commit 32f88df

Please sign in to comment.