-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
152 lines (134 loc) Β· 4.79 KB
/
Copy pathdeploy.sh
File metadata and controls
152 lines (134 loc) Β· 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
BUILD_PATH=$(ls /home/ubuntu/app/server-0.0.1-SNAPSHOT.jar)
JAR_NAME=$(basename $BUILD_PATH)
echo "> build νμΌλͺ
: $JAR_NAME"
echo "> build νμΌ λ³΅μ¬"
DEPLOY_PATH=/home/ubuntu/app/nonstop/jar/
cp $BUILD_PATH $DEPLOY_PATH
echo "> νμ¬ κ΅¬λμ€μΈ Set νμΈ"
CURRENT_PROFILE=$(curl -s http://localhost/profile)
echo "> $CURRENT_PROFILE"
# μ¬κ³ μλ set μ°ΎκΈ°: set1μ΄ μ¬μ©μ€μ΄λ©΄ set2κ° μ¬κ³ μκ³ , λ°λλ©΄ set1μ΄ μ¬κ³ μμ
if [ $CURRENT_PROFILE == set1 ]
then
IDLE_PROFILE=set2
IDLE_PORT=8082
elif [ $CURRENT_PROFILE == set2 ]
then
IDLE_PROFILE=set1
IDLE_PORT=8081
else
echo "> μΌμΉνλ Profileμ΄ μμ΅λλ€. Profile: $CURRENT_PROFILE"
echo "> set1μ ν λΉν©λλ€. IDLE_PROFILE: set1"
IDLE_PROFILE=set1
IDLE_PORT=8081
fi
echo "> application.jar κ΅μ²΄"
IDLE_APPLICATION=$IDLE_PROFILE-Runnect-Spring-Boot-Server.jar
IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION
ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH
echo "> $IDLE_PROFILE μμ ꡬλμ€μΈ μ ν리μΌμ΄μ
pid νμΈ"
IDLE_PID=$(pgrep -f $IDLE_APPLICATION)
if [ -z $IDLE_PID ]
then
echo "> νμ¬ κ΅¬λμ€μΈ μ ν리μΌμ΄μ
μ΄ μμΌλ―λ‘ μ’
λ£νμ§ μμ΅λλ€."
else
echo "> kill -15 $IDLE_PID"
kill -15 $IDLE_PID
sleep 20
fi
echo "> $IDLE_PROFILE λ°°ν¬"
nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
echo "> $IDLE_PROFILE 10μ΄ ν Health check μμ"
echo "> curl -s http://localhost:$IDLE_PORT/health "
sleep 10
for retry_count in {1..10}
do
response=$(curl -s http://localhost:$IDLE_PORT/actuator/health)
up_count=$(echo $response | grep 'UP' | wc -l)
if [ $up_count -ge 1 ]
then # $up_count >= 1 ("UP" λ¬Έμμ΄μ΄ μλμ§ κ²μ¦)
echo "> Health check μ±κ³΅"
break
else
echo "> Health checkμ μλ΅μ μ μ μκ±°λ νΉμ statusκ° UPμ΄ μλλλ€."
echo "> Health check: ${response}"
fi
if [ $retry_count -eq 10 ]
then
echo "> Health check μ€ν¨. "
echo "> Nginxμ μ°κ²°νμ§ μκ³ λ°°ν¬λ₯Ό μ’
λ£ν©λλ€."
exit 1
fi
echo "> Health check μ°κ²° μ€ν¨. μ¬μλ..."
sleep 10
done
echo "> Nginx μν νμΈ λ° λ³΅κ΅¬"
sudo systemctl stop nginx 2>/dev/null || true
sleep 1
sudo systemctl start nginx
sleep 2
if sudo systemctl is-active --quiet nginx; then
echo "> Nginx μμ μ±κ³΅"
else
echo "> Nginx μμ μ€ν¨. κ°μ μ¬μμ μλ..."
sudo killall nginx 2>/dev/null || true
sleep 1
sudo nginx
sleep 2
fi
echo "> λ°©νλ²½ κ·μΉ μ΄κΈ°ν (μΈλ°μ΄λ νΈλν½ νμ©)"
# UFW λΉνμ±ν
sudo ufw disable 2>/dev/null || true
# iptables μ΄κΈ°ν - λͺ¨λ νΈλν½ νμ©
sudo iptables -P INPUT ACCEPT 2>/dev/null || true
sudo iptables -P FORWARD ACCEPT 2>/dev/null || true
sudo iptables -P OUTPUT ACCEPT 2>/dev/null || true
sudo iptables -F 2>/dev/null || true
sudo iptables -X 2>/dev/null || true
echo "> μ€μμΉ"
sleep 10
/home/ubuntu/app/nonstop/switch.sh
echo "> λ°°ν¬ μλ£. μ§λ¨ μ 보 μΆλ ₯ (logTail μΊ‘μ²μ©)..."
echo "=========================================="
echo "=== [DIAG] Public IP ==="
curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null || echo "λ©νλ°μ΄ν° μ κ·Ό λΆκ°"
echo ""
echo "=== [DIAG] Instance ID ==="
curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null || echo "λ©νλ°μ΄ν° μ κ·Ό λΆκ°"
echo ""
echo "=== [DIAG] Security Groups ==="
curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/security-groups 2>/dev/null || echo "λ©νλ°μ΄ν° μ κ·Ό λΆκ°"
echo ""
echo "=== [DIAG] Listening Ports ==="
sudo ss -tlnp 2>/dev/null | head -20
echo ""
echo "=== [DIAG] Nginx Status ==="
sudo systemctl is-active nginx 2>&1
echo ""
echo "=== [DIAG] Java Processes ==="
pgrep -a java 2>/dev/null | head -5
echo ""
echo "=== [DIAG] iptables ==="
sudo iptables -L -n 2>/dev/null | head -20
echo ""
echo "=== [DIAG] UFW Status ==="
sudo ufw status 2>/dev/null
echo ""
echo "=== [DIAG] Network Interfaces ==="
ip addr show 2>/dev/null | grep -E "inet |state" | head -10
echo ""
echo "=== [DIAG] Localhost Tests ==="
echo "8081: $(curl -s -o /dev/null -w '%{http_code}' http://localhost:8081/actuator/health 2>/dev/null)"
echo "8082: $(curl -s -o /dev/null -w '%{http_code}' http://localhost:8082/actuator/health 2>/dev/null)"
echo "80: $(curl -s -o /dev/null -w '%{http_code}' http://localhost/actuator/health 2>/dev/null)"
echo "profile: $(curl -s http://localhost/profile 2>/dev/null)"
echo ""
echo "=== [DIAG] Memory ==="
free -h 2>/dev/null | head -3
echo ""
echo "=== [DIAG] nohup.out (last 20 lines) ==="
tail -20 /home/ubuntu/app/nohup.out 2>/dev/null
echo "=========================================="
echo "> μ§λ¨ μΆλ ₯ μλ£. μλμ μ€ν¨ (logTail μΊ‘μ²)..."
exit 1