Skip to content

Commit

Permalink
Update deploy script: stop the old app by the port
Browse files Browse the repository at this point in the history
  • Loading branch information
vytaux committed Dec 9, 2024
1 parent 3af4528 commit 514557b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ jobs:
- name: Stop old Spring Boot app on EC2
run: |
ssh -i ec2_key.pem -o StrictHostKeyChecking=no ec2-user@${{ secrets.EC2_HOST }} << 'EOF'
PID=$(pgrep -f "app.jar")
PORT=${{ secrets.API_LISTENING_PORT }}
PID=$(sudo netstat -tuln | grep ":$PORT" | awk '{print $7}' | cut -d'/' -f1)
if [ -n "$PID" ]; then
echo "Stopping existing Spring Boot app with PID: $PID"
sudo -E kill $PID
echo "Stopping Spring Boot app running on port $PORT with PID: $PID"
sudo kill $PID
sleep 10
if ps -p $PID > /dev/null; then
echo "Process did not terminate gracefully, force killing."
sudo -E kill -9 $PID
sudo kill -9 $PID
fi
else
echo "No existing Spring Boot app found"
echo "No application running on port $PORT"
fi
EOF
Expand Down

0 comments on commit 514557b

Please sign in to comment.