반응형

[참고] https://levelup.gitconnected.com/how-to-restart-fastapi-server-with-bash-script-f05a5bfcec5c

Uvicorn  프로세스 삭제, 재시작 


nohup uvicorn myapp:app &
ps aux | grep 'uvicorn myapp:app'     # grep --color=auto uvicorn myapp:app
ps aux | grep 'uvicorn myapp:app' | grep -v grep
kill -9 12345  # 해당 PID 12345 삭제, -15가 안전
echo "" > nohup.out
nohup uvicorn myapp:app &


PID=$(ps aux | grep 'uvicorn myapp:app' | grep -v grep | awk {'print $2'} | xargs)
# kill -9 $PID
if [ "$PID" != "" ]
then
kill -9 $PID
sleep 2
echo "" > nohup.out
echo "Restarting FastAPI server"
else
echo "No such process. Starting new FastAPI server"
fi


[restart_server.sh]  worker 설정 없을 때 nohup uvicorn myapp:app &
#!/bin/bash
source /home/project/myenv/bin/activate
cd /home/project/server
PID=$(ps aux | grep 'uvicorn myapp:app' | grep -v grep | awk {'print $2'} | xargs)
if [ "$PID" != "" ]
then
kill -9 $PID
sleep 2
echo "" > nohup.out
echo "Restarting FastAPI server"
else
echo "No such process. Starting new FastAPI server"
fi
nohup uvicorn myapp:app &


[restart_server.sh]  worker 설정 있을 때  nohup uvicorn myapp:app --workers 4 &
#!/bin/bash
source /home/project/myenv/bin/activate
cd /home/project/server
PID=$(ps aux | grep 'uvicorn myapp:app' | grep -v grep | awk {'print $2'} | xargs)
if [ "$PID" != "" ]
then
kill -9 $PID
PID=$(ps aux | grep '/home/project/myenv/bin/python -c from multiprocessing' | grep -v grep | awk {'print $2'} | xargs)
if [ "$PID" != "" ]
then
kill -9 $PID
fi
sleep 2
echo "" > nohup.out
echo "Restarting FastAPI server"
else
echo "No such process. Starting new FastAPI server"
fi
nohup uvicorn myapp:app &

반응형

+ Recent posts