Skip to content

Commit

Permalink
chore: ec2 systemctl 방식에서 nohup 방식으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wonu606 authored Feb 20, 2024
1 parent 0cab9de commit ed17ffc
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env bash

REPOSITORY=/home/ubuntu/studay
cd $REPOSITORY
# 기본 설정: 리포지토리와 애플리케이션 이름
REPOSITORY="/home/ubuntu/studay"
APP_NAME="studay"

APP_NAME=studay
JAR_NAME=$(ls $REPOSITORY/build/libs/*.jar | grep 'SNAPSHOT.jar' | tail -n 1)
JAR_PATH=$JAR_NAME
# 최신 JAR 파일 경로 확인
cd "$REPOSITORY"
LATEST_JAR=$(ls ./build/libs/*SNAPSHOT.jar | tail -n 1)

# systemd 서비스를 중지합니다.
sudo systemctl stop $APP_NAME.service
# 실행 중인 애플리케이션 종료 로직
CURRENT_PID=$(pgrep -f "$LATEST_JAR")
if [[ -n $CURRENT_PID ]]; then
echo "종료할 프로세스 PID: $CURRENT_PID"
kill $CURRENT_PID
# 프로세스 종료 대기
while ps -p $CURRENT_PID &>/dev/null; do
sleep 1
done
fi

# 심볼릭 링크를 이용하여 새로운 JAR 파일로 서비스를 업데이트합니다.
ln -sf $JAR_PATH /home/ubuntu/studay/$APP_NAME-latest.jar
# 심볼릭 링크 업데이트
SYMLINK_PATH="/home/ubuntu/studay/$APP_NAME-latest.jar"
ln -sf "$LATEST_JAR" "$SYMLINK_PATH"

# systemd 서비스를 시작합니다.
sudo systemctl start $APP_NAME.service

# 서비스의 상태를 확인합니다.
sudo systemctl status $APP_NAME.service
# 애플리케이션 백그라운드 실행
nohup java -jar "$SYMLINK_PATH" &>/dev/null &

0 comments on commit ed17ffc

Please sign in to comment.