Skip to content

Commit 7ec068a

Browse files
committed
chore: EC2 리부트 워크플로우 추가 (임시)
1 parent 503ef8a commit 7ec068a

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

.github/workflows/ec2-reboot.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: EC2-REBOOT
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
reboot:
8+
name: Reboot EC2 Instance
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Configure AWS credentials
13+
uses: aws-actions/configure-aws-credentials@v1
14+
with:
15+
aws-access-key-id: ${{ secrets.AWS_PROD_ACCESS_KEY }}
16+
aws-secret-access-key: ${{ secrets.AWS_PROD_SECRET_KEY }}
17+
aws-region: ap-northeast-2
18+
19+
- name: Find EC2 instance
20+
id: find-ec2
21+
run: |
22+
echo "=== 모든 EC2 인스턴스 조회 ==="
23+
aws ec2 describe-instances \
24+
--query "Reservations[].Instances[].[InstanceId, PublicIpAddress, State.Name, Tags[?Key=='Name'].Value | [0]]" \
25+
--output table
26+
27+
echo ""
28+
echo "=== Public IP 3.35.195.11 으로 검색 ==="
29+
INSTANCE_ID=$(aws ec2 describe-instances \
30+
--filters "Name=ip-address,Values=3.35.195.11" \
31+
--query "Reservations[].Instances[].InstanceId" \
32+
--output text)
33+
34+
if [ -z "$INSTANCE_ID" ]; then
35+
echo "Public IP로 찾지 못함. 실행 중인 모든 인스턴스 확인..."
36+
INSTANCE_ID=$(aws ec2 describe-instances \
37+
--filters "Name=instance-state-name,Values=running,stopped" \
38+
--query "Reservations[].Instances[].InstanceId" \
39+
--output text)
40+
fi
41+
42+
echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_OUTPUT
43+
echo "찾은 Instance ID: $INSTANCE_ID"
44+
45+
- name: Reboot EC2 instance
46+
run: |
47+
INSTANCE_ID="${{ steps.find-ec2.outputs.INSTANCE_ID }}"
48+
if [ -n "$INSTANCE_ID" ]; then
49+
echo "EC2 리부트 시작: $INSTANCE_ID"
50+
aws ec2 reboot-instances --instance-ids $INSTANCE_ID
51+
echo "리부트 명령 전송 완료!"
52+
53+
echo "60초 대기 후 상태 확인..."
54+
sleep 60
55+
56+
aws ec2 describe-instances \
57+
--instance-ids $INSTANCE_ID \
58+
--query "Reservations[].Instances[].[InstanceId, PublicIpAddress, State.Name]" \
59+
--output table
60+
else
61+
echo "ERROR: 인스턴스를 찾을 수 없습니다!"
62+
exit 1
63+
fi
64+
65+
- name: Health check
66+
run: |
67+
echo "서버 헬스 체크 시작 (최대 3분 대기)..."
68+
for i in $(seq 1 18); do
69+
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")
70+
echo "[$i/18] HTTP: $HTTP_CODE"
71+
if [ "$HTTP_CODE" = "200" ]; then
72+
echo "서버 복구 완료!"
73+
exit 0
74+
fi
75+
sleep 10
76+
done
77+
echo "WARNING: 서버가 아직 응답하지 않습니다. EC2는 리부트되었지만 앱 시작에 시간이 더 필요할 수 있습니다."

0 commit comments

Comments
 (0)