CodeDeploy 스크립트 추가

This commit is contained in:
Klaus 2023-07-21 19:45:23 +09:00
parent ca875b5baa
commit 1b43baf12d
4 changed files with 48 additions and 2 deletions

18
appspec.yml Normal file
View File

@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user
overwrite: yes
hooks:
ApplicationStart:
- location: scripts/run_process.sh # ApplicationStart 단계에서 해당 파일을 실행해라
timeout: 60
runas: ec2-user
ApplicationStop:
- location: scripts/kill_process.sh # ApplicationStart 단계에서 해당 파일을 실행해라
timeout: 100
runas: ec2-user

16
scripts/kill_process.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
BUILD_JAR=$(ls /home/ec2-user/build/libs/*.jar) # jar가 위치하는 곳
JAR_NAME=$(basename $BUILD_JAR)
echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/deploy.log
echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/deploy.log
CURRENT_PID=$(pgrep -f $JAR_NAME)
if [ -z $CURRENT_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/deploy.log
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

12
scripts/run_process.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
BUILD_JAR=$(ls /home/ec2-user/build/libs/*.jar) # jar가 위치하는 곳
JAR_NAME=$(basename $BUILD_JAR)
echo "> build 파일 복사" >> /home/ec2-user/deploy.log
DEPLOY_PATH=/home/ec2-user/
cp $BUILD_JAR $DEPLOY_PATH
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo "> DEPLOY_JAR 배포" >> /home/ec2-user/deploy.log
chmod +x $DEPLOY_JAR
nohup java -jar $DEPLOY_JAR >> /home/ec2-user/deploy.log 2> /dev/null < /dev/null &

View File

@ -4,8 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class SodaliveApplication
class SodaLiveApplication
fun main(args: Array<String>) {
runApplication<SodaliveApplication>(*args)
runApplication<SodaLiveApplication>(*args)
}