<commit_before>#!/bin/bash
#
set -e # exit on errors
#
if [ $# -gt 1 ]
then
  echo "Usage: $0 username"
  echo " * Note: username is the account that owns the query-gateway process."
  echo " * If omitted username defaults to 'scoopadmin'"
  exit
fi
USERNAME='scoopadmin'
if [ $# -eq 1 ]
then
  USERNAME="$1"
fi
export USERNAME
##
## Create bin/start-endpoint.sh
##
if [ ! -d $HOME/bin ]
then
  mkdir $HOME/bin
fi
#
cat > $HOME/bin/start-endpoint.sh << 'EOF1'
#!/bin/bash
export HOME=/home/scoopadmin
source $HOME/.bash_profile
source $HOME/.bashrc
#
#echo "Starting relay service on port 3000"
#$HOME/endpoint/query-gateway/util/relay-service.rb >> $HOME/logs/rs.log 2>&1 &
#
echo "Starting Query Gateway on port 3001"
cd $HOME/endpoint/query-gateway
if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
then
  bundle exec $HOME/endpoint/query-gateway/script/delayed_job stop
  rm $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid
fi
#
bundle exec $HOME/endpoint/query-gateway/script/delayed_job start
#
# Start gateway
# If gateway is already running (or has a stale server.pid), try to stop it.
if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
then
  kill `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
  then
    kill -9 `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  fi
  rm $HOME/endpoint/query-gateway/tmp/pids/server.pid
fi
bundle exec rails server -p 3001 -d
#/bin/ps -ef | grep "rails server -p 3001" | grep -v grep | awk '{print $2}' > tmp/pids/server.pid
#
#cd $HOME/logs
#tail -f rs.log
EOF1
#
sed -i "s/scoopadmin/$USERNAME/g" $HOME/bin/start-endpoint.sh
##
## Create bin/stop-endpoint.sh
##
cat > $HOME/bin/stop-endpoint.sh << 'EOF2'
#!/bin/bash
export HOME=/home/scoopadmin
source $HOME/.bash_profile
source $HOME/.bashrc
cd $HOME/endpoint/query-gateway
if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
then
  bundle exec $HOME/endpoint/query-gateway/script/delayed_job stop
  # pid file should be gone but recheck
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
  then
    rm $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid
  fi
fi
#
# If gateway is running, stop it.
if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
then
  kill `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
  then
    kill -9 `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  fi
  rm $HOME/endpoint/query-gateway/tmp/pids/server.pid
fi
EOF2
#
sed -i "s/scoopadmin/$USERNAME/g" $HOME/bin/start-endpoint.sh
#
chmod a+x $HOME/bin/*
#
## Configure monit to enable command-line monit tools
sudo bash -c "cat >> /etc/monit/monitrc" << 'EOF0'
#
# needed so that monit command-line tools will work
set httpd port 2812 and
use address localhost
allow localhost
EOF0
##
#
##
## Configure monit to control the query-gateway
##
#!/bin/bash
#
#Setup monit to start query-gateway
sudo bash -c "cat > /etc/monit/conf.d/query-gateway" <<'EOF1'
# Monitor gateway
check process query-gateway with pidfile /home/scoopadmin/endpoint/query-gateway/tmp/pids/server.pid
    start program = "/home/scoopadmin/bin/start-endpoint.sh" as uid scoopadmin and with gid scoopadmin
    stop program = "/home/scoopadmin/bin/stop-endpoint.sh" as uid scoopadmin and with gid scoopadmin
    if 100 restarts within 100 cycles then timeout
EOF1
#
sudo sed -i "s/scoopadmin/$USERNAME/g" /etc/monit/conf.d/query-gateway<commit_msg>Fix typo<commit_after>#!/bin/bash
#
set -e # exit on errors
#
if [ $# -gt 1 ]
then
  echo "Usage: $0 username"
  echo " * Note: username is the account that owns the query-gateway process."
  echo " * If omitted username defaults to 'scoopadmin'"
  exit
fi
USERNAME='scoopadmin'
if [ $# -eq 1 ]
then
  USERNAME="$1"
fi
export USERNAME
##
## Create bin/start-endpoint.sh
##
if [ ! -d $HOME/bin ]
then
  mkdir $HOME/bin
fi
#
cat > $HOME/bin/start-endpoint.sh << 'EOF1'
#!/bin/bash
export HOME=/home/scoopadmin
source $HOME/.bash_profile
source $HOME/.bashrc
#
#echo "Starting relay service on port 3000"
#$HOME/endpoint/query-gateway/util/relay-service.rb >> $HOME/logs/rs.log 2>&1 &
#
echo "Starting Query Gateway on port 3001"
cd $HOME/endpoint/query-gateway
if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
then
  bundle exec $HOME/endpoint/query-gateway/script/delayed_job stop
  rm $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid
fi
#
bundle exec $HOME/endpoint/query-gateway/script/delayed_job start
#
# Start gateway
# If gateway is already running (or has a stale server.pid), try to stop it.
if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
then
  kill `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
  then
    kill -9 `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  fi
  rm $HOME/endpoint/query-gateway/tmp/pids/server.pid
fi
bundle exec rails server -p 3001 -d
#/bin/ps -ef | grep "rails server -p 3001" | grep -v grep | awk '{print $2}' > tmp/pids/server.pid
#
#cd $HOME/logs
#tail -f rs.log
EOF1
#
sed -i "s/scoopadmin/$USERNAME/g" $HOME/bin/start-endpoint.sh
##
## Create bin/stop-endpoint.sh
##
cat > $HOME/bin/stop-endpoint.sh << 'EOF2'
#!/bin/bash
export HOME=/home/scoopadmin
source $HOME/.bash_profile
source $HOME/.bashrc
cd $HOME/endpoint/query-gateway
if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
then
  bundle exec $HOME/endpoint/query-gateway/script/delayed_job stop
  # pid file should be gone but recheck
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid ];
  then
    rm $HOME/endpoint/query-gateway/tmp/pids/delayed_job.pid
  fi
fi
#
# If gateway is running, stop it.
if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
then
  kill `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  if [ -f $HOME/endpoint/query-gateway/tmp/pids/server.pid ];
  then
    kill -9 `cat $HOME/endpoint/query-gateway/tmp/pids/server.pid`
  fi
  rm $HOME/endpoint/query-gateway/tmp/pids/server.pid
fi
EOF2
#
sed -i "s/scoopadmin/$USERNAME/g" $HOME/bin/stop-endpoint.sh
#
chmod a+x $HOME/bin/*
#
## Configure monit to enable command-line monit tools
sudo bash -c "cat >> /etc/monit/monitrc" << 'EOF0'
#
# needed so that monit command-line tools will work
set httpd port 2812 and
use address localhost
allow localhost
EOF0
##
#
##
## Configure monit to control the query-gateway
##
#!/bin/bash
#
#Setup monit to start query-gateway
sudo bash -c "cat > /etc/monit/conf.d/query-gateway" <<'EOF1'
# Monitor gateway
check process query-gateway with pidfile /home/scoopadmin/endpoint/query-gateway/tmp/pids/server.pid
    start program = "/home/scoopadmin/bin/start-endpoint.sh" as uid scoopadmin and with gid scoopadmin
    stop program = "/home/scoopadmin/bin/stop-endpoint.sh" as uid scoopadmin and with gid scoopadmin
    if 100 restarts within 100 cycles then timeout
EOF1
#
sudo sed -i "s/scoopadmin/$USERNAME/g" /etc/monit/conf.d/query-gateway
{'fraction_non_alphanumeric': 0.14045584045584045, 'fraction_numerical': 0.01225071225071225, 'mean_word_length': 3.750338294993234, 'pattern_counts': {'":': 0, '<': 19, '<?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': '3922604', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2586, 'n_words': 648}