EC2-READ-LOGTAIL #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: EC2-RECOVERY | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| recover: | |
| name: Recover Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_PROD_ACCESS_KEY }} | |
| aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_KEY }} | |
| aws-region: ap-northeast-2 | |
| - name: Check IAM identity | |
| run: | | |
| echo "=== IAM 정보 확인 ===" | |
| aws sts get-caller-identity || echo "STS 호출 실패" | |
| - name: Check CodeDeploy deployments | |
| run: | | |
| echo "=== 최근 배포 상태 확인 ===" | |
| aws deploy list-deployments \ | |
| --application-name runnect-prod-codedeploy \ | |
| --deployment-group-name runnect-prod-codedeploy-group \ | |
| --include-only-statuses "Succeeded,Failed,InProgress" \ | |
| --query "deployments[:3]" \ | |
| --output text || echo "배포 목록 조회 실패" | |
| LATEST=$(aws deploy list-deployments \ | |
| --application-name runnect-prod-codedeploy \ | |
| --deployment-group-name runnect-prod-codedeploy-group \ | |
| --query "deployments[0]" \ | |
| --output text 2>/dev/null) | |
| if [ -n "$LATEST" ] && [ "$LATEST" != "None" ]; then | |
| echo "" | |
| echo "=== 최신 배포 상세 ===" | |
| aws deploy get-deployment --deployment-id "$LATEST" \ | |
| --query "deploymentInfo.{status:status, createTime:createTime, completeTime:completeTime, errorInfo:errorInformation}" \ | |
| --output json | |
| fi | |
| - name: Trigger new CodeDeploy deployment | |
| run: | | |
| echo "=== 새 CodeDeploy 배포 트리거 ===" | |
| DEPLOYMENT_ID=$(aws deploy create-deployment \ | |
| --application-name runnect-prod-codedeploy \ | |
| --deployment-group-name runnect-prod-codedeploy-group \ | |
| --file-exists-behavior OVERWRITE \ | |
| --s3-location bucket=runnect-prod-bucket,bundleType=zip,key=runnect_prod_server.zip \ | |
| --region ap-northeast-2 \ | |
| --query "deploymentId" \ | |
| --output text) | |
| echo "Deployment ID: $DEPLOYMENT_ID" | |
| echo "배포 완료 대기 (최대 5분)..." | |
| for i in $(seq 1 30); do | |
| STATUS=$(aws deploy get-deployment --deployment-id "$DEPLOYMENT_ID" \ | |
| --query "deploymentInfo.status" --output text 2>/dev/null) | |
| echo "[$i/30] Status: $STATUS" | |
| if [ "$STATUS" = "Succeeded" ]; then | |
| echo "배포 성공!" | |
| break | |
| elif [ "$STATUS" = "Failed" ] || [ "$STATUS" = "Stopped" ]; then | |
| echo "배포 실패! 상세 정보:" | |
| aws deploy get-deployment --deployment-id "$DEPLOYMENT_ID" \ | |
| --query "deploymentInfo.errorInformation" --output json | |
| break | |
| fi | |
| sleep 10 | |
| done | |
| - name: Health check | |
| run: | | |
| echo "서버 헬스 체크 (최대 3분 대기)..." | |
| for i in $(seq 1 18); do | |
| HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 http://3.35.195.11/actuator/health 2>/dev/null || echo "000") | |
| echo "[$i/18] HTTP: $HTTP_CODE" | |
| if [ "$HTTP_CODE" = "200" ]; then | |
| echo "서버 복구 완료!" | |
| exit 0 | |
| fi | |
| sleep 10 | |
| done | |
| echo "" | |
| echo "=== 포트별 체크 ===" | |
| for PORT in 80 8081 8082; do | |
| HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 --max-time 10 http://3.35.195.11:$PORT/actuator/health 2>/dev/null || echo "000") | |
| echo "Port $PORT: HTTP $HTTP_CODE" | |
| done | |
| echo "WARNING: 서버가 아직 응답하지 않습니다." |