From 13722a08935d52b34a3c09dea6b343ae7720c2fa Mon Sep 17 00:00:00 2001 From: Minju-Kimm Date: Thu, 22 Aug 2024 22:03:53 +0900 Subject: [PATCH] ci/cd setting --- appspec.yml | 23 +++++++++++++++++++++++ build.gradle | 3 +++ nohup.out | 1 + scripts/start.sh | 22 ++++++++++++++++++++++ scripts/stop.sh | 20 ++++++++++++++++++++ src/main/resources/application.yaml | 3 ++- 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 appspec.yml create mode 100644 nohup.out create mode 100644 scripts/start.sh create mode 100644 scripts/stop.sh diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..c3cf81a --- /dev/null +++ b/appspec.yml @@ -0,0 +1,23 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/app + overwrite: yes + +permissions: + - 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 diff --git a/build.gradle b/build.gradle index 1006686..2e6c3f3 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,9 @@ java { } } +jar { + enabled = false +} configurations { compileOnly { extendsFrom annotationProcessor diff --git a/nohup.out b/nohup.out new file mode 100644 index 0000000..2266876 --- /dev/null +++ b/nohup.out @@ -0,0 +1 @@ +Error: Unable to access jarfile demo-0.0.1-SNAPSHOT.jar diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..ba40453 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,22 @@ +# scripts/start.sh +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/app" +JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" + +APP_LOG="$PROJECT_ROOT/application.log" +ERROR_LOG="$PROJECT_ROOT/error.log" +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +# build 파일 복사 +echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG +cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE + +# jar 파일 실행 +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 > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..d7eddcc --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,20 @@ +# scripts/stop.sh +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/app" +JAR_FILE="$PROJECT_ROOT/spring-webapp.jar" + +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 "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG + kill -15 $CURRENT_PID +fi diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index dcf9028..970ae9d 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -27,4 +27,5 @@ spring: password: 'Alswn1858!' driver-class-name: com.mysql.cj.jdbc.Driver username: root - url: jdbc:mysql://127.0.0.1:3306/toilet_db \ No newline at end of file + url: jdbc:mysql://my-rds-instance.c7ooggw06nqt.ap-northeast-2.rds.amazonaws.com + :3306/my_rds_name \ No newline at end of file