-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
114 lines (97 loc) Β· 4.13 KB
/
Copy pathdeploy.sh
File metadata and controls
114 lines (97 loc) Β· 4.13 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
#!/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"
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 μμ"
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
echo "> Health check μ±κ³΅"
break
else
echo "> Health checkμ μλ΅μ μ μ μκ±°λ νΉμ statusκ° UPμ΄ μλλλ€."
fi
if [ $retry_count -eq 10 ]
then
echo "> Health check μ€ν¨."
exit 1
fi
sleep 10
done
echo "> Nginx 볡ꡬ"
sudo systemctl stop nginx 2>/dev/null || true
sleep 1
sudo systemctl start nginx
sleep 2
echo "> λ°©νλ²½ μ΄κΈ°ν"
sudo ufw disable 2>/dev/null || true
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
echo "> μ€μμΉ"
sleep 10
/home/ubuntu/app/nonstop/switch.sh
echo "======= DIAG START ======="
echo "[IP] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null || echo NONE)"
echo "[INST] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null || echo NONE)"
echo "[SG] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/security-groups 2>/dev/null || echo NONE)"
echo "[MAC] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/mac 2>/dev/null || echo NONE)"
MAC=$(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/mac 2>/dev/null)
if [ -n "$MAC" ]; then
echo "[VPC] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-id 2>/dev/null || echo NONE)"
echo "[SUBNET] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/subnet-id 2>/dev/null || echo NONE)"
echo "[SG-IDS] $(curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/security-group-ids 2>/dev/null || echo NONE)"
fi
echo "[NGINX] $(sudo systemctl is-active nginx 2>&1)"
echo "[PORTS] $(sudo ss -tlnp 2>/dev/null | grep -E ':(80|8081|8082) ' || echo NONE)"
echo "[JAVA] $(pgrep -a java 2>/dev/null | head -2 || echo NONE)"
echo "[UFW] $(sudo ufw status 2>/dev/null | head -1)"
echo "[IPT] $(sudo iptables -S 2>/dev/null | head -5)"
echo "[LOCAL80] $(curl -s -o /dev/null -w '%{http_code}' http://localhost/actuator/health 2>/dev/null)"
echo "[LOCAL8081] $(curl -s -o /dev/null -w '%{http_code}' http://localhost:8081/actuator/health 2>/dev/null)"
echo "[LOCAL8082] $(curl -s -o /dev/null -w '%{http_code}' http://localhost:8082/actuator/health 2>/dev/null)"
echo "[PROFILE] $(curl -s http://localhost/profile 2>/dev/null)"
echo "[MEM] $(free -m 2>/dev/null | grep Mem | awk '{print $2"M total, "$3"M used, "$4"M free"}')"
echo "======= DIAG END ======="
exit 1