@@ -11,7 +11,6 @@ echo "> 현재 구동중인 Set 확인"
1111CURRENT_PROFILE=$( curl -s http://localhost/profile)
1212echo " > $CURRENT_PROFILE "
1313
14- # 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음
1514if [ $CURRENT_PROFILE == set1 ]
1615then
1716 IDLE_PROFILE=set2
@@ -49,7 +48,6 @@ echo "> $IDLE_PROFILE 배포"
4948nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
5049
5150echo " > $IDLE_PROFILE 10초 후 Health check 시작"
52- echo " > curl -s http://localhost:$IDLE_PORT /health "
5351sleep 10
5452
5553for retry_count in {1..10}
5856 up_count=$( echo $response | grep ' UP' | wc -l)
5957
6058 if [ $up_count -ge 1 ]
61- then # $up_count >= 1 ("UP" 문자열이 있는지 검증)
59+ then
6260 echo " > Health check 성공"
6361 break
6462 else
6563 echo " > Health check의 응답을 알 수 없거나 혹은 status가 UP이 아닙니다."
66- echo " > Health check: ${response} "
6764 fi
6865
6966 if [ $retry_count -eq 10 ]
7067 then
71- echo " > Health check 실패. "
72- echo " > Nginx에 연결하지 않고 배포를 종료합니다."
68+ echo " > Health check 실패."
7369 exit 1
7470 fi
7571
76- echo " > Health check 연결 실패. 재시도..."
7772 sleep 10
7873done
7974
80- echo " > Nginx 상태 확인 및 복구"
75+ echo " > Nginx 복구"
8176sudo systemctl stop nginx 2> /dev/null || true
8277sleep 1
8378sudo systemctl start nginx
8479sleep 2
85- if sudo systemctl is-active --quiet nginx; then
86- echo " > Nginx 시작 성공"
87- else
88- echo " > Nginx 시작 실패. 강제 재시작 시도..."
89- sudo killall nginx 2> /dev/null || true
90- sleep 1
91- sudo nginx
92- sleep 2
93- fi
9480
95- echo " > 방화벽 규칙 초기화 (인바운드 트래픽 허용)"
96- # UFW 비활성화
81+ echo " > 방화벽 초기화"
9782sudo ufw disable 2> /dev/null || true
98-
99- # iptables 초기화 - 모든 트래픽 허용
10083sudo iptables -P INPUT ACCEPT 2> /dev/null || true
10184sudo iptables -P FORWARD ACCEPT 2> /dev/null || true
10285sudo iptables -P OUTPUT ACCEPT 2> /dev/null || true
10386sudo iptables -F 2> /dev/null || true
104- sudo iptables -X 2> /dev/null || true
10587
10688echo " > 스위칭"
10789sleep 10
10890/home/ubuntu/app/nonstop/switch.sh
10991
110- echo " > 배포 완료. 진단 정보 출력 (logTail 캡처용)..."
111- echo " =========================================="
112- echo " === [DIAG] Public IP ==="
113- curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2> /dev/null || echo " 메타데이터 접근 불가"
114- echo " "
115- echo " === [DIAG] Instance ID ==="
116- curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null || echo " 메타데이터 접근 불가"
117- echo " "
118- echo " === [DIAG] Security Groups ==="
119- curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/security-groups 2> /dev/null || echo " 메타데이터 접근 불가"
120- echo " "
121- echo " === [DIAG] Listening Ports ==="
122- sudo ss -tlnp 2> /dev/null | head -20
123- echo " "
124- echo " === [DIAG] Nginx Status ==="
125- sudo systemctl is-active nginx 2>&1
126- echo " "
127- echo " === [DIAG] Java Processes ==="
128- pgrep -a java 2> /dev/null | head -5
129- echo " "
130- echo " === [DIAG] iptables ==="
131- sudo iptables -L -n 2> /dev/null | head -20
132- echo " "
133- echo " === [DIAG] UFW Status ==="
134- sudo ufw status 2> /dev/null
135- echo " "
136- echo " === [DIAG] Network Interfaces ==="
137- ip addr show 2> /dev/null | grep -E " inet |state" | head -10
138- echo " "
139- echo " === [DIAG] Localhost Tests ==="
140- echo " 8081: $( curl -s -o /dev/null -w ' %{http_code}' http://localhost:8081/actuator/health 2> /dev/null) "
141- echo " 8082: $( curl -s -o /dev/null -w ' %{http_code}' http://localhost:8082/actuator/health 2> /dev/null) "
142- echo " 80: $( curl -s -o /dev/null -w ' %{http_code}' http://localhost/actuator/health 2> /dev/null) "
143- echo " profile: $( curl -s http://localhost/profile 2> /dev/null) "
144- echo " "
145- echo " === [DIAG] Memory ==="
146- free -h 2> /dev/null | head -3
147- echo " "
148- echo " === [DIAG] nohup.out (last 20 lines) ==="
149- tail -20 /home/ubuntu/app/nohup.out 2> /dev/null
150- echo " =========================================="
151- echo " > 진단 출력 완료. 의도적 실패 (logTail 캡처)..."
92+ echo " ======= DIAG START ======="
93+ echo " [IP] $( curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/public-ipv4 2> /dev/null || echo NONE) "
94+ echo " [INST] $( curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null || echo NONE) "
95+ echo " [SG] $( curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/security-groups 2> /dev/null || echo NONE) "
96+ echo " [MAC] $( curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/mac 2> /dev/null || echo NONE) "
97+ MAC=$( curl -s --connect-timeout 3 http://169.254.169.254/latest/meta-data/mac 2> /dev/null)
98+ if [ -n " $MAC " ]; then
99+ 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) "
100+ 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) "
101+ 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) "
102+ fi
103+ echo " [NGINX] $( sudo systemctl is-active nginx 2>&1 ) "
104+ echo " [PORTS] $( sudo ss -tlnp 2> /dev/null | grep -E ' :(80|8081|8082) ' || echo NONE) "
105+ echo " [JAVA] $( pgrep -a java 2> /dev/null | head -2 || echo NONE) "
106+ echo " [UFW] $( sudo ufw status 2> /dev/null | head -1) "
107+ echo " [IPT] $( sudo iptables -S 2> /dev/null | head -5) "
108+ echo " [LOCAL80] $( curl -s -o /dev/null -w ' %{http_code}' http://localhost/actuator/health 2> /dev/null) "
109+ echo " [LOCAL8081] $( curl -s -o /dev/null -w ' %{http_code}' http://localhost:8081/actuator/health 2> /dev/null) "
110+ echo " [LOCAL8082] $( curl -s -o /dev/null -w ' %{http_code}' http://localhost:8082/actuator/health 2> /dev/null) "
111+ echo " [PROFILE] $( curl -s http://localhost/profile 2> /dev/null) "
112+ echo " [MEM] $( free -m 2> /dev/null | grep Mem | awk ' {print $2"M total, "$3"M used, "$4"M free"}' ) "
113+ echo " ======= DIAG END ======="
152114exit 1
0 commit comments