<commit_before>#!/bin/bash
service postgresql start
service redis-server start # Required for celery and caching

pip install -q -r /support/requirements.txt

if [ -z "$APP_ROOT" ]; then
    export APP_ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
fi

if [ -z "$APP_NAME" ]; then
    export APP_NAME=$(basename $(dirname $(find $APP_ROOT -name settings.py | head -n 1)))
fi

pid_file=/var/run/${APP_NAME}_django.pid
server_out=$APP_ROOT/django.log
server_err=$APP_ROOT/error.log

# The APP_PORT global is set
if [ -z "$APP_PORT" ]; then
    export APP_PORT=3000
fi

if [ -n "$1" ]; then
    port="$1"
fi


if pid=$(cat $pid_file); then
    if kill $pid 2>/dev/null; then
        echo "Killed running server (pid: $pid)";
    elif kill -0 $pid 2>/dev/null; then
        echo "Could not kill the running server (pid: $pid)"
        exit 1
    fi

    # Either we've killed the process, or the pid file was out of date
    rm -f $pid_file
fi;

# Prefer Python 3:
PYTHON_BIN=$(which python3 || which python)

echo "Applying any outstanding migrations"
$PYTHON_BIN $APP_ROOT/manage.py migrate

# Start Celery:
if [ "$DJANGO_MODE" != "production" ]; then
    celery_opts=" --autoreload"
fi
echo "Starting celery worker and celerybeat"
# Force Celery to run as root
export C_FORCE_ROOT=1
$PYTHON_BIN $APP_ROOT/manage.py celeryd_detach -B $celery_opts

echo "Starting Django.  Logging output to: $(readlink -f $server_out)"
$PYTHON_BIN $APP_ROOT/manage.py runserver 0.0.0.0:$APP_PORT >>$server_out 2>>$server_err &

if (($?)); then
    echo "I encountered an error while trying to start Django."
    exit 1;
fi


<commit_msg>Start celery worker and beat separately<commit_after>#!/bin/bash
service postgresql start
service redis-server start # Required for celery and caching

pip install -q -r /support/requirements.txt

if [ -z "$APP_ROOT" ]; then
    export APP_ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
fi

if [ -z "$APP_NAME" ]; then
    export APP_NAME=$(basename $(dirname $(find $APP_ROOT -name settings.py | head -n 1)))
fi

pid_file=/var/run/${APP_NAME}_django.pid
server_out=$APP_ROOT/django.log
server_err=$APP_ROOT/error.log

# The APP_PORT global is set
if [ -z "$APP_PORT" ]; then
    export APP_PORT=3000
fi

if [ -n "$1" ]; then
    port="$1"
fi


if pid=$(cat $pid_file); then
    if kill $pid 2>/dev/null; then
        echo "Killed running server (pid: $pid)";
    elif kill -0 $pid 2>/dev/null; then
        echo "Could not kill the running server (pid: $pid)"
        exit 1
    fi

    # Either we've killed the process, or the pid file was out of date
    rm -f $pid_file
fi;

# Prefer Python 3:
PYTHON_BIN=$(which python3 || which python)

echo "Applying any outstanding migrations"
$PYTHON_BIN $APP_ROOT/manage.py migrate

# Start Celery:
if [ "$DJANGO_MODE" != "production" ]; then
    # The --autoreload option results in very high CPU usage on
    # my machine...

    #celery_opts=" --autoreload --loglevel=INFO"
    celery_opts=" --loglevel=INFO"
fi

echo "Starting Django.  Logging output to: $(readlink -f $server_out)"
$PYTHON_BIN $APP_ROOT/manage.py runserver 0.0.0.0:$APP_PORT >>$server_out 2>>$server_err &

echo "Starting celery beat and worker"
# Force Celery to run as root
export C_FORCE_ROOT=1
$PYTHON_BIN $APP_ROOT/manage.py celerybeat --detach || (echo "celery beat failed!" && exit 1)
$PYTHON_BIN $APP_ROOT/manage.py celery worker -B $celery_opts

if (($?)); then
    echo "I encountered an error while trying to start Django."
    exit 1;
fi



{'fraction_non_alphanumeric': 0.1283299914064738, 'fraction_numerical': 0.012317387568032082, 'mean_word_length': 3.687248322147651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3573708', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1205, 'n_words': 403}