<commit_before>#!/bin/bash

DEFAULT_LOG_LEVEL=info
DEFAULT_IP=0.0.0.0
DEFAULT_PORT=8000
DEFAULT_GUNICORN_WORKERS_COUNT=10
DEFAULT_FORCE_DB_MIGRATIONS_ON_START=false

LOOM_LOG_LEVEL=${LOOM_LOG_LEVEL:-$DEFAULT_LOG_LEVEL}
LOOM_SERVER_INTERNAL_IP=${LOOM_SERVER_INTERNAL_IP:-$DEFAULT_IP}
LOOM_SERVER_INTERNAL_PORT=${LOOM_SERVER_INTERNAL_PORT:-$DEFAULT_PORT}
LOOM_SERVER_GUNICORN_WORKERS_COUNT=${LOOM_SERVER_GUNICORN_WORKERS_COUNT:-$DEFAULT_GUNICORN_WORKERS_COUNT}
FORCE_DB_MIGRATIONS_ON_START=${LOOM_FORCE_DB_MIGRATIONS_ON_START:-$DEFAULT_FORCE_DB_MIGRATIONS_ON_START}

for item in true TRUE True t T yes YES Yes y Y
do
    if [ "$FORCE_MIGRATEDB_ON_START" == "$item" ]; then
        FORCE_DB_MIGRATIONS_ON_START=true
        break
    fi
done

for item in true TRUE True t T yes YES Yes y Y
do
    if [ "$LOOM_REQUIRE_LOGIN" == "$item" ]; then
        REQUIRE_LOGIN=true
        break
    fi
done

BIN_PATH="`dirname \"$0\"`"

# Wait for database to become available
RETRIES=10
n=0
while :
do
    # break if db connection is successful
    loom-manage inspectdb > /dev/null 2>&1 && break

    # exit if retries exceeded
    if [ $n -ge $RETRIES ]
    then
	>&2 echo "Timeout while waiting for database"
	exit 1;
    fi
    sleep 5
    n=$[$n+1]
    echo "Could not reach database. Retry $n/$RETRIES."
done

if [ "$FORCE_DB_MIGRATIONS_ON_START" == "true" ]; then
    echo "Applying database migrations"
    python $BIN_PATH/migratedb.py
else
    echo "Verifying that database is initialized"
    python $BIN_PATH/migratedb.py --skip-if-initialized
fi

if [ "$REQUIRE_LOGIN" == "true" ]; then
    echo "Creating admin user $LOOM_ADMIN_USERNAME"
    echo "from django.contrib.auth.models import User; User.objects.create_superuser('$LOOM_ADMIN_USERNAME', '', '$LOOM_ADMIN_PASSWORD')" | loom-manage shell || true
fi
gunicorn loomengine_server.core.wsgi --bind ${LOOM_SERVER_INTERNAL_IP}:${LOOM_SERVER_INTERNAL_PORT} --log-level ${LOOM_LOG_LEVEL} --capture-output -w ${LOOM_SERVER_GUNICORN_WORKERS_COUNT} --timeout 300<commit_msg>bugfix in admin account creation<commit_after>#!/bin/bash

DEFAULT_LOG_LEVEL=info
DEFAULT_IP=0.0.0.0
DEFAULT_PORT=8000
DEFAULT_GUNICORN_WORKERS_COUNT=10
DEFAULT_FORCE_DB_MIGRATIONS_ON_START=false

LOOM_LOG_LEVEL=${LOOM_LOG_LEVEL:-$DEFAULT_LOG_LEVEL}
LOOM_SERVER_INTERNAL_IP=${LOOM_SERVER_INTERNAL_IP:-$DEFAULT_IP}
LOOM_SERVER_INTERNAL_PORT=${LOOM_SERVER_INTERNAL_PORT:-$DEFAULT_PORT}
LOOM_SERVER_GUNICORN_WORKERS_COUNT=${LOOM_SERVER_GUNICORN_WORKERS_COUNT:-$DEFAULT_GUNICORN_WORKERS_COUNT}
FORCE_DB_MIGRATIONS_ON_START=${LOOM_FORCE_DB_MIGRATIONS_ON_START:-$DEFAULT_FORCE_DB_MIGRATIONS_ON_START}

for item in true TRUE True t T yes YES Yes y Y
do
    if [ "$FORCE_MIGRATEDB_ON_START" == "$item" ]; then
        FORCE_DB_MIGRATIONS_ON_START=true
        break
    fi
done

for item in true TRUE True t T yes YES Yes y Y
do
    if [ "$LOOM_LOGIN_REQUIRED" == "$item" ]; then
        LOGIN_REQUIRED=true
        break
    fi
done

BIN_PATH="`dirname \"$0\"`"

# Wait for database to become available
RETRIES=10
n=0
while :
do
    # break if db connection is successful
    loom-manage inspectdb > /dev/null 2>&1 && break

    # exit if retries exceeded
    if [ $n -ge $RETRIES ]
    then
	>&2 echo "Timeout while waiting for database"
	exit 1;
    fi
    sleep 5
    n=$[$n+1]
    echo "Could not reach database. Retry $n/$RETRIES."
done

if [ "$FORCE_DB_MIGRATIONS_ON_START" == "true" ]; then
    echo "Applying database migrations"
    python $BIN_PATH/migratedb.py
else
    echo "Verifying that database is initialized"
    python $BIN_PATH/migratedb.py --skip-if-initialized
fi

if [ "$LOGIN_REQUIRED" == "true" ]; then
    echo "Creating admin user $LOOM_ADMIN_USERNAME"
    echo "from django.contrib.auth.models import User; User.objects.create_superuser('$LOOM_ADMIN_USERNAME', '', '$LOOM_ADMIN_PASSWORD')" | loom-manage shell || true
fi
gunicorn loomengine_server.core.wsgi --bind ${LOOM_SERVER_INTERNAL_IP}:${LOOM_SERVER_INTERNAL_PORT} --log-level ${LOOM_LOG_LEVEL} --capture-output -w ${LOOM_SERVER_GUNICORN_WORKERS_COUNT} --timeout 300
{'fraction_non_alphanumeric': 0.10236220472440945, 'fraction_numerical': 0.011318897637795276, 'mean_word_length': 4.815450643776824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '184025', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1513, 'n_words': 323}