Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions .github/workflows/ec2-reboot.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -16,38 +16,39 @@ 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"

for DEP_ID in $DEPLOYMENTS; do
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
90 changes: 26 additions & 64 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
Loading