<commit_before>#!/bin/bash

set -e

RUN_DIR=/var/vcap/sys/run/nfsv3driver
PIDFILE=$RUN_DIR/nfsv3driver.pid
LOG_DIR=/var/vcap/sys/log/nfsv3driver
LOGFILE=$LOG_DIR/drain.log
ADDRESS=<%=p("nfsv3driver.admin_addr")%>

mkdir -p $LOG_DIR

exec 3>&1

exec 1>> $LOGFILE
exec 2>> $LOGFILE

evacuate() {
  curl --fail --silent http://$ADDRESS/evacuate >/dev/null 2>&1
}

heartbeat() {
  curl --fail --silent http://$ADDRESS/ping >/dev/null 2>&1
}

output_for_bosh() {
  exit_code=$?

  if [ $exit_code -eq 0 ]; then
    echo "$(date): nfsv3driver exited"
  else
    echo "$(date): evacuation failed"
  fi

  echo $exit_code >&3
}

trap output_for_bosh EXIT

if [ ! -f $PIDFILE ]; then
  echo "$(date): PIDFILE does not exist"
  exit 0
fi

pid=$(cat $PIDFILE)

if [ ! -e /proc/$pid ]; then
  echo "$(date): nfsv3driver process not running"
  exit 0
fi

# wait for rep
while pgrep -x "rep_as_vcap" > /dev/null; do
    echo "$(date): waiting for rep..."<commit_msg>drain script waits for 'rep' not 'rep_as_vcap' in order to be more future-proof [#146031059](https://www.pivotaltracker.com/story/show/146031059)<commit_after>#!/bin/bash

set -e

RUN_DIR=/var/vcap/sys/run/nfsv3driver
PIDFILE=$RUN_DIR/nfsv3driver.pid
LOG_DIR=/var/vcap/sys/log/nfsv3driver
LOGFILE=$LOG_DIR/drain.log
ADDRESS=<%=p("nfsv3driver.admin_addr")%>

mkdir -p $LOG_DIR

exec 3>&1

exec 1>> $LOGFILE
exec 2>> $LOGFILE

evacuate() {
  curl --fail --silent http://$ADDRESS/evacuate >/dev/null 2>&1
}

heartbeat() {
  curl --fail --silent http://$ADDRESS/ping >/dev/null 2>&1
}

output_for_bosh() {
  exit_code=$?

  if [ $exit_code -eq 0 ]; then
    echo "$(date): nfsv3driver exited"
  else
    echo "$(date): evacuation failed"
  fi

  echo $exit_code >&3
}

trap output_for_bosh EXIT

if [ ! -f $PIDFILE ]; then
  echo "$(date): PIDFILE does not exist"
  exit 0
fi

pid=$(cat $PIDFILE)

if [ ! -e /proc/$pid ]; then
  echo "$(date): nfsv3driver process not running"
  exit 0
fi

# wait for rep
while pgrep -x "rep" > /dev/null; do
    echo "$(date): waiting for rep..."
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.026627218934911243, 'mean_word_length': 3.590497737556561, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '112028', 'n_tokens_mistral': 889, 'n_tokens_neox': 829, 'n_words': 208}