-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
163 lines (132 loc) Β· 4.37 KB
/
Copy pathdeploy.sh
File metadata and controls
163 lines (132 loc) Β· 4.37 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
153
154
155
156
157
158
159
160
161
162
163
#!/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 μν νμΈ"
if ! sudo systemctl is-active --quiet nginx; then
echo "> Nginxκ° μ€μ§λμ΄ μμ΅λλ€. μ¬μμν©λλ€."
sudo systemctl start nginx
sleep 2
if sudo systemctl is-active --quiet nginx; then
echo "> Nginx μ¬μμ μ±κ³΅"
else
echo "> Nginx μ¬μμ μ€ν¨. μν:"
sudo systemctl status nginx
fi
else
echo "> Nginx μ μ ꡬλ μ€"
fi
echo "> μ€μμΉ"
sleep 10
/home/ubuntu/app/nonstop/switch.sh
echo "> λ°°ν¬ μλ£. μ§λ¨ μ 보 μμ§ μ€..."
DIAG_FILE="/tmp/server-diagnostic-$(date +%Y%m%d-%H%M%S).txt"
{
echo "========== SERVER DIAGNOSTIC =========="
echo "Date: $(date)"
echo ""
echo "=== Public IP (EC2 metadata) ==="
curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null || echo "λ©νλ°μ΄ν° μ κ·Ό λΆκ°"
echo ""
echo "=== Network Interfaces ==="
ip addr show 2>/dev/null || ifconfig 2>/dev/null
echo ""
echo "=== Nginx Status ==="
sudo systemctl status nginx 2>&1
echo ""
echo "=== Nginx Config ==="
sudo nginx -T 2>&1
echo ""
echo "=== Listening Ports ==="
sudo ss -tlnp 2>/dev/null || sudo netstat -tlnp 2>/dev/null
echo ""
echo "=== Java Processes ==="
pgrep -a java 2>/dev/null || echo "Java νλ‘μΈμ€ μμ"
echo ""
echo "=== iptables Rules ==="
sudo iptables -L -n 2>/dev/null || echo "iptables μ‘°ν μ€ν¨"
echo ""
echo "=== Localhost Health Check ==="
curl -s http://localhost:8081/actuator/health 2>/dev/null
echo ""
curl -s http://localhost:8082/actuator/health 2>/dev/null
echo ""
curl -s http://localhost/actuator/health 2>/dev/null
echo ""
curl -s http://localhost/profile 2>/dev/null
echo ""
echo "=== Disk Usage ==="
df -h 2>/dev/null
echo ""
echo "=== Memory Usage ==="
free -h 2>/dev/null
echo ""
echo "=== nohup.out (last 50 lines) ==="
tail -50 /home/ubuntu/app/nohup.out 2>/dev/null || echo "nohup.out μμ"
echo ""
echo "========== END DIAGNOSTIC =========="
} > "$DIAG_FILE" 2>&1
echo "> μ§λ¨ κ²°κ³Όλ₯Ό S3μ μ
λ‘λ..."
aws s3 cp "$DIAG_FILE" s3://runnect-prod-bucket/diagnostics/$(basename "$DIAG_FILE") 2>&1 || echo "> S3 μ
λ‘λ μ€ν¨"
echo "> μ§λ¨ μλ£"