diff --git a/start b/start index 2214092..fa09f82 100755 --- a/start +++ b/start @@ -10,6 +10,18 @@ if ! test -f "$SCRIPT_DIR/.undercover_init_successful"; then 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 echo "Entering virtual environment..." source "$SCRIPT_DIR/.venv/bin/activate" @@ -23,9 +35,9 @@ fi if [[ "$1" == "prod" ]]; then echo "Starting gunicorn production server..." - gunicorn -b "localhost:$PROD_PORT" "app:create_app()" + may-init gunicorn -b "localhost:$PROD_PORT" "app:create_app()" else echo "Starting local dev server..." export FLASK_APP=app - flask --debug run --host=0.0.0.0 + may-init flask --debug run --host=0.0.0.0 fi