<commit_before>#!/bin/bash
trap handle_term TERM INT

function app_exit {
    # Sleep forever so the process does not complete
    while [ ${APP_EXIT:-false} == false ]
    do
        sleep 1
    done
    exit 0
}

function check_reverse_proxy {
    grep -e "^spark\.ui\.reverseProxy" $SPARK_HOME/conf/spark-defaults.conf &> /dev/null
    if [ "$?" -ne 0 ]; then
        echo "Appending default reverse proxy config to spark-defaults.conf"
        echo "spark.ui.reverseProxy              true" >> $SPARK_HOME/conf/spark-defaults.conf
        echo "spark.ui.reverseProxyUrl           /" >> $SPARK_HOME/conf/spark-defaults.conf
    fi
}

function get_deployment {
    # If this fails because the file is not there or the label isn't present, then
    # DEPLOYMENT will be an empty string
    DEPLOYMENT=$(grep "^deployment=" /etc/podinfo/labels | cut -d'=' -f2- | tr -d '"')
}

function delete_ephemeral {
    local appstatus=$1
    local line
    echo "Deleting cluster '$OSHINKO_CLUSTER_NAME'"
    if [ "$ephemeral" == "<shared>" ]; then
        echo "cluster is not ephemeral"
        echo "cluster not deleted '$OSHINKO_CLUSTER_NAME'"
    else
        line=$($CLI delete_eph $OSHINKO_CLUSTER_NAME --app=$POD_NAME --app-status=$1 $CLI_ARGS 2>&1)
        echo $line
    fi
}

function handle_term {
    echo Received a termination signal

    # If we've saved a PID for a subprocess, kill that first before
    # trying to delete the cluster
    local cnt
    local killed=1
    if [ -n "$PID" ]; then
        echo "Stopping subprocess $PID"
        kill -TERM $PID
        for cnt in {1..10} 
        do
            kill -0 $PID >/dev/null 2>&1
            if [ "$?" -ne 0 ]; then
                killed=0
                break
            else
                sleep 1
            fi
        done
        if [ "$killed" -ne 0 ]; then
            echo Process is still running 10 seconds after TERM, sending KILL
            kill -9 $PID
        fi
        wait $PID
        echo "Subprocess stopped"
    fi

    # Tell delete_ephemeral that we are calling because of a signal received
    # before or during the spark-submit call.
    delete_ephemeral terminated
    if [  ${TEST_MODE:-false} == true ]; then
        echo Test mode delaying 10 seconds before exit
        sleep 10
    fi
    exit 0
}

function exit_flag {
    # Set APP_EXIT to true and ignore the signal, so the normal loop will fall out
    echo Received a termination signal
    if [  ${TEST_MODE:-false} == true ]; then
        echo Test mode delaying 10 seconds before exit
        sleep 10
    fi
    echo Setting app_exit true on signal handler
    APP_EXIT=true
}

function get_app_file {
    if [ -z "$APP_FILE"]; then
        case "$APP_LANG" in
            java | scala)
                file_count "*.jar"
                ;;
            python)
                file_count "*.py"
                ;;
            r)
                file_count "*.R"
                ;;
            *)
                echo "Unrecognized value '$APP_LANG' for APP_LANG and APP_FILE not set"
                app_exit
                ;;
        esac<commit_msg>fix spacing error in start.sh<commit_after>#!/bin/bash
trap handle_term TERM INT

function app_exit {
    # Sleep forever so the process does not complete
    while [ ${APP_EXIT:-false} == false ]
    do
        sleep 1
    done
    exit 0
}

function check_reverse_proxy {
    grep -e "^spark\.ui\.reverseProxy" $SPARK_HOME/conf/spark-defaults.conf &> /dev/null
    if [ "$?" -ne 0 ]; then
        echo "Appending default reverse proxy config to spark-defaults.conf"
        echo "spark.ui.reverseProxy              true" >> $SPARK_HOME/conf/spark-defaults.conf
        echo "spark.ui.reverseProxyUrl           /" >> $SPARK_HOME/conf/spark-defaults.conf
    fi
}

function get_deployment {
    # If this fails because the file is not there or the label isn't present, then
    # DEPLOYMENT will be an empty string
    DEPLOYMENT=$(grep "^deployment=" /etc/podinfo/labels | cut -d'=' -f2- | tr -d '"')
}

function delete_ephemeral {
    local appstatus=$1
    local line
    echo "Deleting cluster '$OSHINKO_CLUSTER_NAME'"
    if [ "$ephemeral" == "<shared>" ]; then
        echo "cluster is not ephemeral"
        echo "cluster not deleted '$OSHINKO_CLUSTER_NAME'"
    else
        line=$($CLI delete_eph $OSHINKO_CLUSTER_NAME --app=$POD_NAME --app-status=$1 $CLI_ARGS 2>&1)
        echo $line
    fi
}

function handle_term {
    echo Received a termination signal

    # If we've saved a PID for a subprocess, kill that first before
    # trying to delete the cluster
    local cnt
    local killed=1
    if [ -n "$PID" ]; then
        echo "Stopping subprocess $PID"
        kill -TERM $PID
        for cnt in {1..10} 
        do
            kill -0 $PID >/dev/null 2>&1
            if [ "$?" -ne 0 ]; then
                killed=0
                break
            else
                sleep 1
            fi
        done
        if [ "$killed" -ne 0 ]; then
            echo Process is still running 10 seconds after TERM, sending KILL
            kill -9 $PID
        fi
        wait $PID
        echo "Subprocess stopped"
    fi

    # Tell delete_ephemeral that we are calling because of a signal received
    # before or during the spark-submit call.
    delete_ephemeral terminated
    if [  ${TEST_MODE:-false} == true ]; then
        echo Test mode delaying 10 seconds before exit
        sleep 10
    fi
    exit 0
}

function exit_flag {
    # Set APP_EXIT to true and ignore the signal, so the normal loop will fall out
    echo Received a termination signal
    if [  ${TEST_MODE:-false} == true ]; then
        echo Test mode delaying 10 seconds before exit
        sleep 10
    fi
    echo Setting app_exit true on signal handler
    APP_EXIT=true
}

function get_app_file {
    if [ -z "$APP_FILE" ]; then
        case "$APP_LANG" in
            java | scala)
                file_count "*.jar"
                ;;
            python)
                file_count "*.py"
                ;;
            r)
                file_count "*.R"
                ;;
            *)
                echo "Unrecognized value '$APP_LANG' for APP_LANG and APP_FILE not set"
                app_exit
                ;;
        esac
{'fraction_non_alphanumeric': 0.08721395423267723, 'fraction_numerical': 0.00992158745399264, 'mean_word_length': 1.8064660978895375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3728490', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1821, 'n_words': 633}