Skip to content

Instantly share code, notes, and snippets.

@wfng92
Last active January 16, 2024 20:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save wfng92/8211e05134e66285d83a8b06f1c0c7ff to your computer and use it in GitHub Desktop.
Save wfng92/8211e05134e66285d83a8b06f1c0c7ff 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
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