From 65c2fbeda2d2650c406ee943e95118961b1797b3 Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Tue, 24 Feb 2026 09:00:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20logTail=20=EC=9D=BD=EA=B8=B0=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ec2-reboot.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ec2-reboot.yml b/.github/workflows/ec2-reboot.yml index cd04cac..50fd1ce 100644 --- a/.github/workflows/ec2-reboot.yml +++ b/.github/workflows/ec2-reboot.yml @@ -1,11 +1,11 @@ -name: EC2-READ-DEPLOY-LOG +name: EC2-READ-LOGTAIL on: workflow_dispatch: jobs: read-log: - name: Read CodeDeploy Logs + name: Read CodeDeploy LogTail runs-on: ubuntu-latest steps: @@ -16,13 +16,13 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_KEY }} aws-region: ap-northeast-2 - - name: Get deployment lifecycle events + - name: Get latest deployment logTail run: | - echo "=== 최근 배포 목록 (최대 5개) ===" + echo "=== 최근 배포 목록 ===" DEPLOYMENTS=$(aws deploy list-deployments \ --application-name runnect-prod-codedeploy \ --deployment-group-name runnect-prod-codedeploy-group \ - --query "deployments[:5]" \ + --query "deployments[:3]" \ --output text 2>/dev/null) echo "Deployments: $DEPLOYMENTS" @@ -30,24 +30,25 @@ jobs: echo "" echo "================================================" echo "=== Deployment: $DEP_ID ===" - echo "================================================" - aws deploy get-deployment --deployment-id "$DEP_ID" \ - --query "deploymentInfo.{status:status, createTime:createTime, completeTime:completeTime, error:errorInformation}" \ - --output json 2>&1 + DEP_STATUS=$(aws deploy get-deployment --deployment-id "$DEP_ID" \ + --query "deploymentInfo.status" --output text 2>/dev/null) + DEP_TIME=$(aws deploy get-deployment --deployment-id "$DEP_ID" \ + --query "deploymentInfo.createTime" --output text 2>/dev/null) + echo "Status: $DEP_STATUS | Created: $DEP_TIME" - echo "" - echo "--- Instance lifecycle events ---" INSTANCES=$(aws deploy list-deployment-instances \ --deployment-id "$DEP_ID" \ --query "instancesList" \ --output text 2>/dev/null) for INST in $INSTANCES; do - echo "Instance: $INST" + echo "" + echo "--- Instance: $INST ---" aws deploy get-deployment-instance \ --deployment-id "$DEP_ID" \ --instance-id "$INST" \ + --query "instanceSummary.lifecycleEvents[].{name:lifecycleEventName, status:status, logTail:diagnostics.logTail}" \ --output json 2>&1 done done From a3d6f16d4cd9783166c1602e047b0334fd6a8a5c Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Tue, 24 Feb 2026 09:02:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20deploy.sh=20=ED=95=B5=EC=8B=AC=20?= =?UTF-8?q?=EC=A7=84=EB=8B=A8=20=EC=A0=95=EB=B3=B4=EB=A7=8C=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20(logTail=20=EC=B5=9C=EC=A0=81=ED=99=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 90 ++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 64 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index e175868..f890aae 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,7 +11,6 @@ echo "> 현재 구동중인 Set 확인" CURRENT_PROFILE=$(curl -s http://localhost/profile) echo "> $CURRENT_PROFILE" -# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 if [ $CURRENT_PROFILE == set1 ] then IDLE_PROFILE=set2 @@ -49,7 +48,6 @@ 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} @@ -58,95 +56,59 @@ do up_count=$(echo $response | grep 'UP' | wc -l) if [ $up_count -ge 1 ] - then # $up_count >= 1 ("UP" 문자열이 있는지 검증) + then 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에 연결하지 않고 배포를 종료합니다." + echo "> Health check 실패." exit 1 fi - echo "> Health check 연결 실패. 재시도..." sleep 10 done -echo "> Nginx 상태 확인 및 복구" +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 비활성화 +echo "> 방화벽 초기화" 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 캡처)..." +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