Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save liluo/599597a7e265323b184b31d228955768 to your computer and use it in GitHub Desktop.
Save liluo/599597a7e265323b184b31d228955768 to your computer and use it in GitHub Desktop.
#!/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 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment