<commit_before>#!/usr/bin/env bash
bin=`readlink "$0"`
if [ "$bin" == "" ]; then
 bin=$0
fi
bin=`dirname "$bin"`
bin=`cd "$bin"; pwd`

. "$bin"/chorus-config.sh

command=$1
shift

services=(${@})

function contains() {
    local n=$#
    local value=${!n}
    for ((i=1;i < $#;i++)) {
        if [ "${!i}" == "${value}" ]; then
            return 0
        fi
    }
    return 1
}

function should_handle () {
  # If no services are provided, or $1 is a service to start
  [ ${#services[@]} -eq 0 ] || contains ${services[@]} $1
}

function start () {
  EXIT_STATUS=0
  pushd $CHORUS_HOME > /dev/null
  if should_handle postgres;  then
    $bin/start-postgres.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle workers;   then
    $bin/start-workers.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle scheduler; then
    $bin/start-scheduler.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle solr;      then
    $bin/start-solr.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle webserver; then
    $bin/start-webserver.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  popd > /dev/null
  if (($EXIT_STATUS > 0)); then
    exit $EXIT_STATUS;
  fi
}

function stop () {
  pushd $CHORUS_HOME > /dev/null
  if should_handle webserver;  then $bin/stop-webserver.sh;   fi
  if should_handle solr;       then $bin/stop-solr.sh;        fi
  if should_handle scheduler;  then $bin/stop-scheduler.sh;   fi
  if should_handle workers;    then $bin/stop-workers.sh;     fi
  if should_handle postgres;   then $bin/stop-postgres.sh;    fi
  popd > /dev/null
}

function monitor () {
  echo "Monitoring services..."
  echo
  while true
  do
    start
    sleep 10
    echo
  done
}

function backup () {
  echo "Backing up chorus data..."

  while getopts "d:r:" OPTION
  do
       case $OPTION in
           d)
               BACKUP_DIR=$OPTARG
               ;;
           r)
               ROLLING_DAYS=$OPTARG
               ;;
           ?)
               usage
               exit
               ;;
       esac
  done

  if [ -z "$BACKUP_DIR" ]; then
      usage
      exit
  fi

  mkdir -p "$BACKUP_DIR" || exit 1
  if [ ! -r $BACKUP_DIR ] || [ ! -w $BACKUP_DIR ]; then
      echo "Error: Could not write to directory \"$BACKUP_DIR\"." > /dev/stderr
      exit 1
  fi

  if ! kill -0 `head -1 $POSTGRES_PID_FILE 2>&1` >& /dev/null; then
      postgres_started="1"
      $bin/start-postgres.sh
  fi

   BACKUP_PATH=`cd $BACKUP_DIR && echo $PWD`
   rake "backup:create[$BACKUP_PATH,$ROLLING_DAYS]"

   if [ -n "$postgres_started" ]; then
       $bin/stop-postgres.sh
   fi
}<commit_msg>[#30938105] add default backup directory<commit_after>#!/usr/bin/env bash
bin=`readlink "$0"`
if [ "$bin" == "" ]; then
 bin=$0
fi
bin=`dirname "$bin"`
bin=`cd "$bin"; pwd`

. "$bin"/chorus-config.sh

command=$1
shift

services=(${@})

function contains() {
    local n=$#
    local value=${!n}
    for ((i=1;i < $#;i++)) {
        if [ "${!i}" == "${value}" ]; then
            return 0
        fi
    }
    return 1
}

function should_handle () {
  # If no services are provided, or $1 is a service to start
  [ ${#services[@]} -eq 0 ] || contains ${services[@]} $1
}

function start () {
  EXIT_STATUS=0
  pushd $CHORUS_HOME > /dev/null
  if should_handle postgres;  then
    $bin/start-postgres.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle workers;   then
    $bin/start-workers.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle scheduler; then
    $bin/start-scheduler.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle solr;      then
    $bin/start-solr.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  if should_handle webserver; then
    $bin/start-webserver.sh;
    EXIT_STATUS=`expr $EXIT_STATUS + $?`;
  fi
  popd > /dev/null
  if (($EXIT_STATUS > 0)); then
    exit $EXIT_STATUS;
  fi
}

function stop () {
  pushd $CHORUS_HOME > /dev/null
  if should_handle webserver;  then $bin/stop-webserver.sh;   fi
  if should_handle solr;       then $bin/stop-solr.sh;        fi
  if should_handle scheduler;  then $bin/stop-scheduler.sh;   fi
  if should_handle workers;    then $bin/stop-workers.sh;     fi
  if should_handle postgres;   then $bin/stop-postgres.sh;    fi
  popd > /dev/null
}

function monitor () {
  echo "Monitoring services..."
  echo
  while true
  do
    start
    sleep 10
    echo
  done
}

function backup () {
  pushd $CHORUS_HOME > /dev/null

  echo "Backing up chorus data..."

  BACKUP_DIR="data/chorus/bak"

  while getopts "d:r:" OPTION
  do
       case $OPTION in
           d)
               BACKUP_DIR=$OPTARG
               ;;
           r)
               ROLLING_DAYS=$OPTARG
               ;;
           ?)
               usage
               exit
               ;;
       esac
  done

  if [ -z "$BACKUP_DIR" ]; then
      usage
      exit
  fi

  mkdir -p "$BACKUP_DIR" || exit 1
  if [ ! -r $BACKUP_DIR ] || [ ! -w $BACKUP_DIR ]; then
      echo "Error: Could not write to directory \"$BACKUP_DIR\"." > /dev/stderr
      exit 1
  fi

  if ! kill -0 `head -1 $POSTGRES_PID_FILE 2>&1` >& /dev/null; then
      postgres_started="1"
      $bin/start-postgres.sh
  fi

  BACKUP_PATH=`cd $BACKUP_DIR && echo $PWD`
  rake "backup:create[$BACKUP_PATH,$ROLLING_DAYS]"

  if [ -n "$postgres_started" ]; then
      $bin/stop-postgres.sh
  fi

  popd > /dev/null
}
{'fraction_non_alphanumeric': 0.1414085545722714, 'fraction_numerical': 0.008849557522123894, 'mean_word_length': 2.250449370880767, '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': '1178787', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1986, 'n_words': 488}