#!/bin/bash

INST_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "$INST_DIR/config"
cd $PROJ_ROOT

mkdir -p cache/botanjs

case "$RUN_MODE" in
	"web")
		./botan-rebuild.py
		uwsgi \
			--plugins-dir /usr/lib/uwsgi/ --need-plugin python \
			--http-socket :5000 \
			--wsgi-file main.py \
			--callable application --master \
			--processes 1 --threads 2
		;;
	"tasks")
		source "$INST_DIR/celery.conf"

		celery -A ${CELERY_APP} worker -n worker1@%h \
		  --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} \
		& celery -A ${CELERY_APP} worker -n worker1@%h \
		  --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
		;;
	*)
		echo "RUN_MODE is missing"
		exit 1
		;;
esac