#!/bin/sh

MLIMIT=$((1024*1024))
VLIMIT=$((2*1024*1024))
# The maximum amount of virtual
# memory available to the process
ulimit -v $VLIMIT
# The maximum resident set size
ulimit -m $MLIMIT

APPDIR=/usr/local/streambuilder/ui
LOGDIR=/var/log/streambuilder/ui
[ -d $LOGDIR ] || mkdir -p $LOGDIR

if [ ! -e /etc/logrotate.d/sb-ui ] ; then
cat <<LOGROTATE >/etc/logrotate.d/.sb-ui
$LOGDIR/streambuilder.log {
    missingok
    copytruncate
    delaycompress
    compress
    daily
    rotate 7
    notifempty
}
LOGROTATE
mv /etc/logrotate.d/.sb-ui /etc/logrotate.d/sb-ui
fi

sleep 3
exec 2>&1

export APP_ENV=production
. /usr/local/pyenv/sb.ui/bin/activate
cd $APPDIR
exec python app.py --port=23001
