Change deploy.yml #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 to Server | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| cd /home/ubuntu/ | |
| # 1. Git Pull erzwingen und Erfolg vortäuschen, egal was passiert | |
| git pull origin main || echo "Git pull nicht notwendig oder fehlgeschlagen, mache trotzdem weiter..." | |
| # 2. Bestehende App beenden (das '|| true' ist hier der Lebensretter!) | |
| # Es verhindert, dass das Signal 143 den Workflow killt. | |
| sudo pkill -f "python3 app.py" || true | |
| # 3. Pufferzeit, damit der Port (z.B. 5000) wirklich frei wird | |
| sleep 2 | |
| # 4. Der "Hintergrund-Start", der die Verbindung überlebt | |
| # Wir leiten ALLES um (> /dev/null), damit SSH sofort fertig ist | |
| nohup python3 app.py > app.log 2>&1 & | |
| # 5. Den Prozess vom Terminal abkoppeln | |
| disown | |
| echo "Deployment-Skript beendet. App sollte im Hintergrund laufen." |