#!/bin/bash

BASE=data/gunicorn

source .venv/bin/activate
export FLASK_APP=wowstash/app.py
export FLASK_SECRETS=config.py
export FLASK_DEBUG=0
export FLASK_ENV=production

mkdir -p $BASE

pgrep -F $BASE/gunicorn.pid

if [[ $? != 0 ]]; then
  gunicorn \
    --bind 127.0.0.1:4001 "wowstash.app:app" \
    --daemon \
    --log-file $BASE/gunicorn.log \
    --pid $BASE/gunicorn.pid \
    --reload
  sleep 1
  echo "Starting gunicorn with pid $(cat $BASE/gunicorn.pid)"
fi
