Skip to content

Commit bd9216a

Browse files
committed
fix: sync dev appspec/deploy.sh with current Amazon Linux deployment style
dev ๋ธŒ๋žœ์น˜์˜ appspec.yml/deploy.sh๊ฐ€ ์˜ˆ์ „ Ubuntu + blue-green ๋ฐฉ์‹(set1/set2, /home/ubuntu)์— ๋จธ๋ฌผ๋Ÿฌ ์žˆ์–ด์„œ Amazon Linux ๊ธฐ๋ฐ˜ ์Šคํ…Œ์ด์ง• ์ธ์Šคํ„ด์Šค์— ๋ฐฐํฌ ์‹œ "can't find user for ubuntu" ์—๋Ÿฌ๋กœ ์‹คํŒจํ•จ. main์— ์ด๋ฏธ ๋ฐ˜์˜๋œ ๋‹จ์ผ ํ”„๋กœ์„ธ์Šค + ec2-user ๋ฐฉ์‹์œผ๋กœ ๋งž์ถค.
1 parent 02b7bc2 commit bd9216a

2 files changed

Lines changed: 37 additions & 88 deletions

File tree

โ€Žappspec.ymlโ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ version: 0.0
22
os: linux
33

44
files:
5-
- source: /
6-
destination: /home/ubuntu/app
5+
- source: /
6+
destination: /home/ec2-user/app
77
overwrite: yes
88

99
permissions:
1010
- object: /
1111
pattern: "**"
12-
owner: ubuntu
13-
group: ubuntu
12+
owner: ec2-user
13+
group: ec2-user
1414

1515
hooks:
1616
AfterInstall:
1717
- location: deploy.sh
1818
timeout: 300
19-
runas: ubuntu
19+
runas: ec2-user

โ€Žscripts/deploy.shโ€Ž

Lines changed: 32 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,45 @@
11
#!/bin/bash
2-
BUILD_PATH=$(ls /home/ubuntu/app/server-0.0.1-SNAPSHOT.jar)
3-
JAR_NAME=$(basename $BUILD_PATH)
4-
echo "> build ํŒŒ์ผ๋ช…: $JAR_NAME"
5-
6-
echo "> build ํŒŒ์ผ ๋ณต์‚ฌ"
7-
DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/
8-
cp $BUILD_PATH $DEPLOY_PATH
9-
10-
echo "> ํ˜„์žฌ ๊ตฌ๋™์ค‘์ธ Set ํ™•์ธ"
11-
CURRENT_PROFILE=$(curl -s http://localhost/profile)
12-
echo "> $CURRENT_PROFILE"
13-
14-
# ์‰ฌ๊ณ  ์žˆ๋Š” set ์ฐพ๊ธฐ: set1์ด ์‚ฌ์šฉ์ค‘์ด๋ฉด set2๊ฐ€ ์‰ฌ๊ณ  ์žˆ๊ณ , ๋ฐ˜๋Œ€๋ฉด set1์ด ์‰ฌ๊ณ  ์žˆ์Œ
15-
if [ $CURRENT_PROFILE == set1 ]
16-
then
17-
IDLE_PROFILE=set2
18-
IDLE_PORT=8082
19-
elif [ $CURRENT_PROFILE == set2 ]
20-
then
21-
IDLE_PROFILE=set1
22-
IDLE_PORT=8081
2+
set -e
3+
4+
APP_DIR=/home/ec2-user/app
5+
JAR_PATH=$(ls $APP_DIR/*.jar | grep -v plain | head -1)
6+
echo "> JAR ํŒŒ์ผ: $JAR_PATH"
7+
8+
echo "> ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ข…๋ฃŒ"
9+
CURRENT_PID=$(pgrep -f '\.jar' || true)
10+
if [ -n "$CURRENT_PID" ]; then
11+
echo "> ์ข…๋ฃŒ: $CURRENT_PID"
12+
kill -15 $CURRENT_PID
13+
sleep 5
2314
else
24-
echo "> ์ผ์น˜ํ•˜๋Š” Profile์ด ์—†์Šต๋‹ˆ๋‹ค. Profile: $CURRENT_PROFILE"
25-
echo "> set1์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. IDLE_PROFILE: set1"
26-
IDLE_PROFILE=set1
27-
IDLE_PORT=8081
15+
echo "> ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์—†์Œ"
2816
fi
2917

30-
echo "> application.jar ๊ต์ฒด"
31-
IDLE_APPLICATION=$IDLE_PROFILE-Runnect-Spring-Boot-Server.jar
32-
IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION
33-
34-
ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH
35-
36-
echo "> $IDLE_PROFILE ์—์„œ ๊ตฌ๋™์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ pid ํ™•์ธ"
37-
IDLE_PID=$(pgrep -f $IDLE_APPLICATION)
38-
39-
if [ -z $IDLE_PID ]
40-
then
41-
echo "> ํ˜„์žฌ ๊ตฌ๋™์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์—†์œผ๋ฏ€๋กœ ์ข…๋ฃŒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
42-
else
43-
echo "> kill -15 $IDLE_PID"
44-
kill -15 $IDLE_PID
45-
sleep 20
46-
fi
18+
echo "> ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹œ์ž‘"
19+
nohup java -jar \
20+
-Duser.timezone=Asia/Seoul \
21+
$JAR_PATH \
22+
>> /home/ec2-user/app/nohup.out 2>&1 &
4723

48-
echo "> $IDLE_PROFILE ๋ฐฐํฌ"
49-
nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
24+
echo "> 15์ดˆ ํ›„ ํ—ฌ์Šค์ฒดํฌ ์‹œ์ž‘"
25+
sleep 15
5026

51-
echo "> $IDLE_PROFILE 10์ดˆ ํ›„ Health check ์‹œ์ž‘"
52-
echo "> curl -s http://localhost:$IDLE_PORT/health "
53-
sleep 10
54-
55-
for retry_count in {1..10}
56-
do
57-
response=$(curl -s http://localhost:$IDLE_PORT/actuator/health)
58-
up_count=$(echo $response | grep 'UP' | wc -l)
59-
60-
if [ $up_count -ge 1 ]
61-
then # $up_count >= 1 ("UP" ๋ฌธ์ž์—ด์ด ์žˆ๋Š”์ง€ ๊ฒ€์ฆ)
62-
echo "> Health check ์„ฑ๊ณต"
63-
break
64-
else
65-
echo "> Health check์˜ ์‘๋‹ต์„ ์•Œ ์ˆ˜ ์—†๊ฑฐ๋‚˜ ํ˜น์€ status๊ฐ€ UP์ด ์•„๋‹™๋‹ˆ๋‹ค."
66-
echo "> Health check: ${response}"
27+
for i in {1..10}; do
28+
RESPONSE=$(curl -s http://localhost:8080/actuator/health || true)
29+
if echo "$RESPONSE" | grep -q '"status":"UP"'; then
30+
echo "> ํ—ฌ์Šค์ฒดํฌ ์„ฑ๊ณต"
31+
break
6732
fi
68-
69-
if [ $retry_count -eq 10 ]
70-
then
71-
echo "> Health check ์‹คํŒจ. "
72-
echo "> Nginx์— ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๊ณ  ๋ฐฐํฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค."
33+
echo "> ํ—ฌ์Šค์ฒดํฌ ์‹คํŒจ($i/10): $RESPONSE"
34+
if [ $i -eq 10 ]; then
35+
echo "> ๋ฐฐํฌ ์‹คํŒจ"
7336
exit 1
7437
fi
75-
76-
echo "> Health check ์—ฐ๊ฒฐ ์‹คํŒจ. ์žฌ์‹œ๋„..."
7738
sleep 10
7839
done
7940

80-
echo "> Nginx ์ƒํƒœ ํ™•์ธ"
81-
if ! sudo systemctl is-active --quiet nginx; then
82-
echo "> Nginx๊ฐ€ ์ค‘์ง€๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค."
83-
sudo systemctl start nginx
84-
sleep 2
85-
if sudo systemctl is-active --quiet nginx; then
86-
echo "> Nginx ์žฌ์‹œ์ž‘ ์„ฑ๊ณต"
87-
else
88-
echo "> Nginx ์žฌ์‹œ์ž‘ ์‹คํŒจ."
89-
fi
90-
else
91-
echo "> Nginx ์ •์ƒ ๊ตฌ๋™ ์ค‘"
92-
fi
41+
echo "> Nginx ์‹œ์ž‘"
42+
sudo systemctl start nginx || true
43+
sudo systemctl enable nginx || true
9344

94-
echo "> ์Šค์œ„์นญ"
95-
sleep 10
96-
/home/ubuntu/app/nonstop/switch.sh
45+
echo "> ๋ฐฐํฌ ์™„๋ฃŒ"

0 commit comments

Comments
ย (0)