Attempt to re-initialize if start fails.

This commit is contained in:
Sage Vaillancourt 2024-09-16 09:47:31 -04:00
parent d9fa6fdf33
commit 7b88673b36
1 changed files with 14 additions and 2 deletions

16
start
View File

@ -10,6 +10,18 @@ if ! test -f "$SCRIPT_DIR/.undercover_init_successful"; then
fi fi
fi fi
function may-init {
if $@; then
return 0
else
echo "Service start failed. Re-initializing."
rm "$SCRIPT_DIR/.undercover_init_successful"
"$SCRIPT_DIR/init"
source "$SCRIPT_DIR/.venv/bin/activate"
$@
fi
}
if ! pip3 -V | grep -E "$SCRIPT_DIR/\.?venv"; then if ! pip3 -V | grep -E "$SCRIPT_DIR/\.?venv"; then
echo "Entering virtual environment..." echo "Entering virtual environment..."
source "$SCRIPT_DIR/.venv/bin/activate" source "$SCRIPT_DIR/.venv/bin/activate"
@ -23,9 +35,9 @@ fi
if [[ "$1" == "prod" ]]; then if [[ "$1" == "prod" ]]; then
echo "Starting gunicorn production server..." echo "Starting gunicorn production server..."
gunicorn -b "localhost:$PROD_PORT" "app:create_app()" may-init gunicorn -b "localhost:$PROD_PORT" "app:create_app()"
else else
echo "Starting local dev server..." echo "Starting local dev server..."
export FLASK_APP=app export FLASK_APP=app
flask --debug run --host=0.0.0.0 may-init flask --debug run --host=0.0.0.0
fi fi