[참고] 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 &
'FastAPI' 카테고리의 다른 글
FastAPI에서 데이터베이스 연결하기 (SQLAlchemy) (0) | 2022.06.10 |
---|---|
Elastic APM을 이용한 FastAPI 모니터링 (0) | 2022.06.10 |
FastAPI, push 기능 (Server sent events) 구현 (0) | 2022.05.19 |
FastAPI와 React Socket 연결 (0) | 2022.05.15 |
FastAPI에서 HTML 형식으로 응답하기 (0) | 2022.05.03 |