Skip to content

Commit

Permalink
Merge pull request #39 from software-project-yu/develop
Browse files Browse the repository at this point in the history
👷ci:script변경
  • Loading branch information
tkv00 authored Nov 19, 2024
2 parents e6582d2 + 7a524aa commit ca9ea06
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
9 changes: 6 additions & 3 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ version: 0.0
os: linux

files:
- source: ./
destination: /home/ubuntu/libs
- source: /
destination: /home/ubuntu/app
overwrite: yes

permissions:
- object: /home/ubuntu/libs
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: scripts/stop.sh
timeout: 60
runas: ubuntu
ApplicationStart:
- location: scripts/start.sh
timeout: 60
runas: ubuntu
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ java {
languageVersion = JavaLanguageVersion.of(21)
}
}
jar {
enabled=false
}

configurations {
compileOnly {
Expand Down
38 changes: 15 additions & 23 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
#!/bin/bash
#!/usr/bin/env bash

# Set the path where your JAR files are located
ROOT_PATH="/home/ubuntu/libs" # Adjust to the correct directory
JAR="$ROOT_PATH/application.jar"
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"

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

NOW=$(date +%c)
TIME_NOW=$(date +%c)

# Log the JAR copy action
echo "[$NOW] $JAR 복사" >> $START_LOG
# build 파일 복사
echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG
cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE

# Adjusted copy path to the build directory, assuming your JAR is in /libs/
cp $ROOT_PATH/spring-github-action-1.0.0.jar $JAR
# jar 파일 실행
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG
nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &

# Log the JAR execution
echo "[$NOW] > $JAR 실행" >> $START_LOG

# Run the application in the background
nohup java -jar $JAR > $APP_LOG 2> $ERROR_LOG &

# Get the service PID
SERVICE_PID=$(pgrep -f $JAR)

# Log the service PID
echo "[$NOW] > 서비스 PID: $SERVICE_PID" >> $START_LOG
CURRENT_PID=$(pgrep -f $JAR_FILE)
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG
27 changes: 16 additions & 11 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash

ROOT_PATH="/home/ubuntu/libs" # JAR 파일이 위치한 디렉토리
JAR="$ROOT_PATH/demo-0.0.1-SNAPSHOT.jar" # 해당 디렉토리 내 JAR 파일
STOP_LOG="$ROOT_PATH/stop.log"
SERVICE_PID=$(pgrep -f $JAR) # 실행중인 Spring 서버의 PID
PROJECT_ROOT="/home/ubuntu/app"
JAR_FILE="$PROJECT_ROOT/spring-webapp.jar"

if [ -z "$SERVICE_PID" ]; then
echo "서비스 NouFound" >> $STOP_LOG
DEPLOY_LOG="$PROJECT_ROOT/deploy.log"

TIME_NOW=$(date +%c)

# 현재 구동 중인 애플리케이션 pid 확인
CURRENT_PID=$(pgrep -f $JAR_FILE)

# 프로세스가 켜져 있으면 종료
if [ -z $CURRENT_PID ]; then
echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG
else
echo "서비스 종료 " >> $STOP_LOG
kill "$SERVICE_PID"
# kill -9 $SERVICE_PID # 강제 종료를 하고 싶다면 이 명령어 사용
fi
echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG
kill -15 $CURRENT_PID
fi

0 comments on commit ca9ea06

Please sign in to comment.