From 4ccdce83f90b4fa45f94ab7e95038eb37c2aa093 Mon Sep 17 00:00:00 2001 From: Darrel Pol Date: Thu, 12 Sep 2024 22:13:32 -0500 Subject: [PATCH] finding process by port --- .github/workflows/on_merge_to_master.yaml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/on_merge_to_master.yaml b/.github/workflows/on_merge_to_master.yaml index b7e3d0595..d0ed42039 100644 --- a/.github/workflows/on_merge_to_master.yaml +++ b/.github/workflows/on_merge_to_master.yaml @@ -25,11 +25,13 @@ jobs: cd /home/ec2-user/apps # Terminate any running instances of the Python app - if pgrep -f "python launch.py" > /dev/null; then - echo "Terminating existing instance of the app..." - pkill -f "python launch.py" + PORT=7860 + PID=$(lsof -t -i:$PORT) + if [ ! -z "$PID" ]; then + echo "Terminating process running on port $PORT with PID $PID..." + kill -9 $PID else - echo "No existing instance found." + echo "No process is running on port $PORT." fi # Check if the stable-diffusion-webui folder exists @@ -71,15 +73,9 @@ jobs: # Return to the main project directory cd .. - # Start the application with nohup and delay - nohup python launch.py --nowebui --listen --api & + # Run the application in the background using nohup + nohup python launch.py --nowebui --listen --api > nohup.out 2>&1 & - # Wait for 60 seconds to allow the application to fully start - sleep 60 - - # Redirect nohup output - > nohup.out 2>&1 - # Detach from the SSH session to prevent hanging exit EOF