UnderCover/start

44 lines
983 B
Plaintext
Raw Normal View History

#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
source $SCRIPT_DIR/env
2022-10-03 16:37:56 -04:00
if ! test -f "$SCRIPT_DIR/.undercover_init_successful"; then
if ! "$SCRIPT_DIR/init"; then
exit 1
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"
fi
2022-10-03 16:37:56 -04:00
PROD_PORT=8080
if [[ "$UNDERCOVER_PROD_PORT" != "" ]]; then
PROD_PORT="$UNDERCOVER_PROD_PORT"
fi
if [[ "$1" == "prod" ]]; then
echo "Starting gunicorn production server..."
may-init gunicorn -b "localhost:$PROD_PORT" "app:create_app()"
else
echo "Starting local dev server..."
2022-10-02 16:32:01 -04:00
export FLASK_APP=app
may-init flask --debug run --host=0.0.0.0
fi