<commit_before>#!/bin/bash

set -e

RUN_DIR=/var/vcap/sys/run/server
export LOG_DIR=/var/vcap/sys/log/server

PIDFILE=${RUN_DIR}/pid

SERVER_DIR=/var/vcap/jobs/server/packages/mc-server
WORLD_DIR=/var/vcap/store/server/<%= properties.server.world_name %>
SETTING_DIR=/var/vcap/jobs/server/data

export JAVA_HOME=/var/vcap/jobs/server/packages/java
export PATH=$JAVA_HOME/bin:$PATH
export PATH=/var/vcap/jobs/server/packages/screen/bin:$PATH

case $1 in

  start)
    mkdir -p $RUN_DIR $LOG_DIR $WORLD_DIR
    chown -R vcap:vcap $RUN_DIR $LOG_DIR $WORLD_DIR

    cd ${SERVER_DIR}

    if [ ! -d "<%= properties.server.world_name %>" ]; then
        ln -s ${WORLD_DIR} <%= properties.server.world_name %>
    fi

    if [ ! -f "server.properties" ]; then
        ln -s ${SETTING_DIR}/* .
    fi

    screen -c ./screen.cfg
    sleep 5
    pgrep -n 'java' > $PIDFILE
    ;;

  stop)
    screen -rx mcs -X stuff "/stop\n"
    sleep 10
    rm -f $PIDFILE

    ;;

  *)
    echo "Usage: ctl {start|stop}" ;;

esac<commit_msg>- Server no longer launched using screen (screen and monit do not play well together) - Added simple logging of ctl script for easier debugging<commit_after>#!/bin/bash

set -ex

export LOG_DIR=/var/vcap/sys/log/server
SCRIPT_LOGFILE=ctl.log

mkdir -p $LOG_DIR
chown -R vcap:vcap $LOG_DIR

echo $$ ": ################# Starting " $(date) "########### pid " $$ > ${LOG_DIR}/${SCRIPT_LOGFILE}

{
    RUN_DIR=/var/vcap/sys/run/server
    PIDFILE=${RUN_DIR}/pid

    SERVER_DIR=/var/vcap/jobs/server/packages/mc-server
    WORLD_DIR=/var/vcap/store/server/<%= properties.server.world_name %>
    SETTING_DIR=/var/vcap/jobs/server/data

    export TERM=screen
    export JAVA_HOME=/var/vcap/jobs/server/packages/java
    export PATH=$JAVA_HOME/bin:$PATH
    export PATH=/var/vcap/jobs/server/packages/screen/bin:$PATH

    case $1 in

      start)

        mkdir -p $RUN_DIR $WORLD_DIR
        chown -R vcap:vcap $RUN_DIR $WORLD_DIR

        echo $$ > ${PIDFILE}

        cd ${SERVER_DIR}

        if [ ! -d "<%= properties.server.world_name %>" ]; then
            ln -s ${WORLD_DIR} <%= properties.server.world_name %>
        fi

        if [ ! -f "server.properties" ]; then
            ln -s ${SETTING_DIR}/* .
        fi

        exec ./ServerStart.sh > ${LOG_DIR}/server-`date +%d%m%Y%T`.log
        ;;

      stop)
        PID=`cat ${PIDFILE}`
        kill -- -$(ps -o pgid= $PID | grep -o '[0-9]*')
        sleep 10
        rm -f $PIDFILE

        ;;

      *)
        echo "Usage: ctl {start|stop}" ;;

    esac

} >> ${LOG_DIR}/${SCRIPT_LOGFILE}
{'fraction_non_alphanumeric': 0.16342412451361868, 'fraction_numerical': 0.003501945525291829, 'mean_word_length': 2.541322314049587, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 15, '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': '2463185', 'n_tokens_mistral': 1042, 'n_tokens_neox': 929, 'n_words': 191}