diff --git a/appspec.yml b/appspec.yml index 806f8c7..df1d0ae 100644 --- a/appspec.yml +++ b/appspec.yml @@ -2,4 +2,10 @@ version: 0.0 os: linux files: - source: / - destination: /home/ubuntu/app/deploy \ No newline at end of file + destination: /home/ubuntu/app/deploy + + #배포가 끝나면 deploy.sh를 실행시킴 (우회하는 방법 사용) +hooks: + AfterInstall: + - location: execute-deploy.sh + timeout: 180 \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..58f55d3 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +echo "> Checking pid of the running application..." + +APP_BASE_PATH=/home/ubuntu/app/ + +CURRENT_PID=$(pgrep -f i-like-this-page) + +echo "PID = $CURRENT_PID" + +if [ -z $CURRENT_PID ]; then + echo "> There is no running application." +else + echo "> kill -15 $CURRENT_PID" + kill -15 $CURRENT_PID + sleep 5 +fi + +echo "> Deploying a new application..." + +echo "> Copy jar files" + +cp $APP_BASE_PATH/deploy/build/libs/*.jar $APP_BASE_PATH/jar/ + +JAR_NAME=$(ls -tr $APP_BASE_PATH/jar/ | grep 'i-like-this-page' | tail -n 1) + +echo "> JAR Name: $JAR_NAME" + +nohup java -jar $APP_BASE_PATH/jar/$JAR_NAME & \ No newline at end of file diff --git a/scripts/execute-deploy.sh b/scripts/execute-deploy.sh new file mode 100644 index 0000000..e6653ea --- /dev/null +++ b/scripts/execute-deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +touch /home/ubuntu/deploy.log + +/home/ubuntu/deploy.sh > /home/ubuntu/deploy.log 2> /home/ubuntu/deploy.log < /dev/null &