From 32f88dff7771d656049ef13169ed2fd778d66178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=81=EC=A7=84?= <59333182+youngreal@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:31:02 +0900 Subject: [PATCH] update start.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 애플리케이션 실행시 이전프로세스 확인 및 실행확인 로직 추가 --- scripts/start.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 648d255..74e6c78 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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 @@ -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