-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: ec2 systemctl 방식에서 nohup 방식으로 수정
- Loading branch information
Showing
1 changed file
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 & |