Last active
July 6, 2021 18:05
-
-
Save brannondorsey/b2f698283880061e4c935180c87aebd7 to your computer and use it in GitHub Desktop.
start_installation.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Launch and installation and its subprocesses. If the subprocesses | |
# go down, re-launch them individually. If this script receives a | |
# shutdown signal (Ctrl-c, etc...), kill the child processes. | |
function on_exit() { | |
kill $BACKEND_PID $FRONTEND_PID | |
exit 0 | |
} | |
function start_backend() { | |
cd backend | |
# maybe you wrote a python backend | |
python server.py & | |
BACKEND_PID=$! | |
cd - | |
} | |
function start_frontend() { | |
cd frontend | |
# maybe you wrote an electron frontend w/ a fancy npm start script | |
npm start & | |
FRONTEND_PID=$! | |
cd - | |
} | |
# put your ENV vars here. For instance, I like to crush | |
# it on my GTX1080Ti | |
export CUDA_VISIBLE_DEVICES=0 | |
# fire on_exit when these signals are caught | |
trap on_exit INT TERM EXIT | |
while true ; do | |
if ! $(kill -0 "$FRONTEND_PID" > /dev/null 2>&1) ; then | |
echo "the frontend quit, re-launching" | |
start_frontend | |
fi | |
if ! $(kill -0 "$BACKEND_PID" > /dev/null 2>&1) ; then | |
echo "the backend quit, re-launching" | |
start_backend | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment