refactor: nohup -> systemd #3
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: Deploy Mission AI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Copy files to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| port: 22 | |
| source: "./" | |
| target: "/home/ubuntu/mission-ai" | |
| - name: Upload .env file | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| port: 22 | |
| script: | | |
| echo "${{ secrets.ENV_FILE }}" > /home/ubuntu/mission-ai/.env | |
| - name: Install dependencies & restart service | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| port: 22 | |
| script: | | |
| cd /home/ubuntu/mission-ai | |
| python3 -m venv venv 2>/dev/null || true | |
| source venv/bin/activate | |
| pip install -r requirements.txt | |
| # 서비스 재시작 | |
| sudo systemctl restart mission | |
| sudo systemctl status mission --no-pager | |
| - name: Health Check | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| port: 22 | |
| script: | | |
| echo "Mission AI 서버 헬스체크 중..." | |
| for i in {1..10}; do | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:6000/health || true) | |
| if [ "$STATUS" == "200" ]; then | |
| echo "Mission AI 서버 헬스체크 성공!" | |
| exit 0 | |
| fi | |
| echo "서버 응답 대기 중... ($i/10)" | |
| sleep 3 | |
| done | |
| echo "Mission AI 헬스체크 실패" | |
| exit 1 |