-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Moyeothon-NewTeams/feature/develop
๐Style: develop -> main
- Loading branch information
Showing
9 changed files
with
177 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: 0.0 #CodeDeploy ๋ฒ์ ์(๋ฌด์กฐ๊ฑด 0.0์ผ๋ก ๊ณ ์ ) | ||
os: linux | ||
files: | ||
- source: / #destination์ผ๋ก ์ด๋์ํฌ ํ์ผ. ์ฌ๊ธฐ์๋ ์ ์ฒด ํ์ผ์ ์๋ฏธ. | ||
destination: /home/ec2-user/app/zip/ #source์์ ์ง์ ๋ ํ์ผ์ ๋ฐ๋ ์์น | ||
overwrite: yes #๊ธฐ์กด ํ์ผ๋ค์ ๋ฎ์ด์ธ์ง ์ฌ๋ถ | ||
|
||
permissions: #CodeDeploy์์ EC2 ์๋ฒ๋ก ๋๊ฒจ์ค ํ์ผ๋ค์ ๋ชจ๋ ec2-user ๊ถํ์ ๊ฐ๋๋ก ํจ | ||
- object: / | ||
pattern: "**" | ||
owner: ec2-user | ||
group: ec2-user | ||
|
||
hooks: | ||
AfterInstall: | ||
- location: stop.sh #์์ง์์ค์ ์ฐ๊ฒฐ๋์ด ์์ง ์์ ์คํ๋ง ๋ถํธ๋ฅผ ์ข ๋ฃ | ||
timeout: 60 | ||
runas: ec2-user #stop.sh๋ฅผ ec2-user ๊ถํ์ผ๋ก ์คํ | ||
ApplicationStart: | ||
- location: start.sh #์์ง์์ค์ ์ฐ๊ฒฐ๋์ด ์์ง ์์ Port๋ก ์ ๋ฒ์ ์ ์คํ๋ง ๋ถํธ๋ฅผ ์์ | ||
timeout: 60 | ||
runas: ec2-user | ||
ValidateService: | ||
- location: health.sh #์ ์คํ๋ง ๋ถํธ๊ฐ ์ ์์ ์ผ๋ก ์คํ๋๋์ง ํ์ธ | ||
timeout: 60 | ||
runas: ec2-user |
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 |
---|---|---|
|
@@ -56,3 +56,7 @@ dependencies { | |
tasks.named('test') { | ||
useJUnitPlatform() | ||
} | ||
|
||
jar{ | ||
enabled = false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
ABSPATH=$(readlink -f $0) | ||
ABSDIR=$(dirname $ABSPATH) | ||
source ${ABSDIR}/profile.sh | ||
source ${ABSDIR}/switch.sh | ||
|
||
IDLE_PORT=$(find_idle_port) | ||
|
||
echo "> Health Check Start!" | ||
echo "> IDLE_PORT: $IDLE_PORT" | ||
echo "> curl -s http://127.0.0.1:$IDLE_PORT/profile" | ||
sleep 10 | ||
|
||
for RETRY_COUNT in {1..10} | ||
do | ||
RESPONSE=$(curl -s http://127.0.0.1:${IDLE_PORT}/profile) | ||
UP_COUNT=$(echo ${RESPONSE} | grep 'real' | wc -l) | ||
|
||
if [ ${UP_COUNT} -ge 1 ] # Nginx์ ์ฐ๊ฒฐ๋์ง ์์ ํฌํธ๋ก ์คํ๋ง ๋ถํธ๊ฐ ์ ์คํ๋์๋์ง ์ฒดํฌ | ||
then # $up_count >= 1 ("real" ๋ฌธ์์ด์ด ์๋์ง ๊ฒ์ฆ) | ||
echo "> Health Check ์ฑ๊ณต" | ||
switch_proxy # ์ ์คํ๋์ด ์๋ค๋ฉด ํ๋ก์ ์ค์ ์ ๋ณ๊ฒฝ | ||
break | ||
else | ||
echo "> Health Check์ ์๋ต์ ์ ์ ์๊ฑฐ๋ ํน์ ์คํ ์ํ๊ฐ ์๋๋๋ค." | ||
echo "> Health Check: ${RESPONSE}" | ||
fi | ||
|
||
if [ ${RETRY_COUNT} -eq 10 ] | ||
then | ||
echo "> Health check ์คํจ. " | ||
echo "> ์์ง์์ค์ ์ฐ๊ฒฐํ์ง ์๊ณ ๋ฐฐํฌ๋ฅผ ์ข ๋ฃํฉ๋๋ค." | ||
exit 1 | ||
fi | ||
|
||
echo "> Health check ์ฐ๊ฒฐ ์คํจ. ์ฌ์๋..." | ||
sleep 10 | ||
done |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
# ์ฌ๊ณ ์๋ profile ์ฐพ๊ธฐ | ||
# real1์ด ์ฌ์ฉ ์ค์ด๋ฉด real2๊ฐ ์ฌ๊ณ ์๊ณ ๋ฐ๋๋ฉด real1์ด ์ฌ๊ณ ์์ | ||
|
||
function find_idle_profile() { | ||
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://newteamsgoody.shop/profile) # ํ์ฌ Nginx๊ฐ ๋ฐ๋ผ๋ณด๊ณ ์๋ ์คํ๋ง ๋ถํธ๊ฐ ์ ์์ ์ผ๋ก ์ํ ์ค์ธ์ง ํ์ธํ๊ณ ์๋ต๊ฐ์ผ๋ก ์ํ์ฝ๋๋ฅผ ์ ๋ฌ๋ฐ์ | ||
|
||
if [ ${RESPONSE_CODE} -ge 400 ] # 400๋ฒ๋ ์ด์์ ์ค๋ฅ์ผ ๊ฒฝ์ฐ real2๋ฅผ ์ฌ์ฉ | ||
then | ||
CURRENT_PROFILE=real2 | ||
else | ||
CURRENT_PROFILE=$(curl -s https://newteamsgoody.shop/profile) | ||
fi | ||
|
||
if [ ${CURRENT_PROFILE} == real1 ] | ||
then | ||
IDLE_PROFILE=real2 | ||
else | ||
IDLE_PROFILE=real1 | ||
fi | ||
|
||
echo "${IDLE_PROFILE}" # bash ์คํฌ๋ฆฝํธ๋ ๋ฐํ ๊ธฐ๋ฅ์ด ์๊ธฐ ๋๋ฌธ์ echo๋ก ๊ฐ์ ์ถ๋ ฅํ๊ณ ํด๋ผ์ด์ธํธ์์ ๊ทธ ๊ฐ์ ์ก์์ ์ฌ์ฉ | ||
} | ||
|
||
# ์ฌ๊ณ ์๋ profile์ port ์ฐพ๊ธฐ | ||
function find_idle_port() { | ||
IDLE_PROFILE=$(find_idle_profile) | ||
|
||
if [ ${IDLE_PROFILE} == real1 ] | ||
then | ||
echo "8081" | ||
else | ||
echo "8082" | ||
fi | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
ABSPATH=$(readlink -f $0) | ||
ABSDIR=$(dirname $ABSPATH) | ||
source ${ABSDIR}/profile.sh | ||
|
||
REPOSITORY=/home/ec2-user/app | ||
|
||
echo "> Build ํ์ผ์ ๋ณต์ฌํฉ๋๋ค." | ||
|
||
cp $REPOSITORY/zip/*.jar $REPOSITORY/ | ||
|
||
echo "> ์ ์ ํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ" | ||
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1) | ||
|
||
echo "> JAR NAME: $JAR_NAME" | ||
|
||
echo "> $JAR_NAME ์ ์คํ ๊ถํ์ ๋ถ์ฌํฉ๋๋ค." | ||
|
||
chmod +x $JAR_NAME | ||
|
||
IDLE_PROFILE=$(find_idle_profile) | ||
|
||
echo "> ์ ์ ํ๋ฆฌ์ผ์ด์ ์ $IDLE_PROFILE ๋ก ์คํํฉ๋๋ค." | ||
|
||
# ์ค์ ํ์ผ์ ์์น๋ฅผ ์ง์ ํ๊ณ active profile์ ํตํด ๊ตฌ๋๋ ํฌํธ๋ฅผ ์ง์ | ||
nohup java -jar \ | ||
-Dspring.config.location=$REPOSITORY/config/application.yml,\ | ||
$REPOSITORY/config/application-prod.yml,\ | ||
$REPOSITORY/config/application-$IDLE_PROFILE.yml \ | ||
-Dspring.profiles.active=$IDLE_PROFILE,prod \ | ||
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 & |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
ABSPATH=$(readlink -f $0) # ํ์ฌ stop.sh๊ฐ ์ํด ์๋ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ | ||
|
||
ABSDIR=$(dirname $ABSPATH) | ||
source ${ABSDIR}/profile.sh # ์ผ์ข ์ import ๊ตฌ๋ฌธ์ผ๋ก stop.sh์์๋ profile.sh์ function์ ์ฌ์ฉํ ์ ์๊ฒ ํจ | ||
|
||
IDLE_PORT=$(find_idle_port) | ||
|
||
echo "> $IDLE_PORT ์์ ๊ตฌ๋ ์ค์ธ ์ ํ๋ฆฌ์ผ์ด์ pid ํ์ธ" | ||
IDLE_PID=$(lsof -ti tcp:${IDLE_PORT}) | ||
|
||
if [ -z ${IDLE_PID} ] | ||
then | ||
echo "> ํ์ฌ ๊ตฌ๋ ์ค์ธ ์ ํ๋ฆฌ์ผ์ด์ ์ด ์์ผ๋ฏ๋ก ์ข ๋ฃํ์ง ์์ต๋๋ค." | ||
else | ||
echo "> kill -9 $IDLE_PID" | ||
kill -9 ${IDLE_PID} | ||
sleep 5 | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
ABSPATH=$(readlink -f $0) | ||
ABSDIR=$(dirname $ABSPATH) | ||
source $ABSDIR/profile.sh | ||
|
||
function switch_proxy() { | ||
IDLE_PORT=$(find_idle_port) | ||
|
||
echo "> ์ ํํ port: $IDLE_PORT" | ||
echo "> Port ์ ํ" | ||
echo "set \$service_url http://127.0.0.1:${IDLE_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc # ์์ง์์ค๊ฐ ๋ณ๊ฒฝํ ํ๋ก์ ์ฃผ์๋ฅผ ์์ฑํ์ฌ service-url.inc๋ก ๋ฎ์ด ์ | ||
|
||
echo "> ์์ง์์ค Reload" | ||
sudo systemctl reload nginx | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8081 |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
server: | ||
port: 8082 |