Change deploy.yml #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: 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. Neuesten Code von GitHub holen | |
| git pull origin main | |
| # 2. Alte Instanz finden und beenden (kill), falls sie läuft | |
| # Wir suchen nach dem Prozess "app.py" und beenden ihn freundlich | |
| sudo pkill -f app.py | |
| sudo pkill -f app.py | |
| # 3. Kurz warten, damit Ports frei werden | |
| sleep 2 | |
| # 4. App mit nohup neu starten | |
| nohup python3 app.py > app.log 2>&1 & disown | |
| echo "Deployment erfolgreich abgeschlossen und App neu gestartet." |