<commit_before>#!/usr/bin/env bash
set -e

SSH_USER="jan" # user to ssh to machines with

#ssh <EMAIL> "cat /etc/redis/6379.conf | grep dbfilename;ls -d1 /var/lib/redis/6379/*.*;cat /etc/redis/6380.conf | grep dbfilename;ls -d1 /var/lib/redis/6380/*.*;"
if [ "testserver" == `hostname` ]; then
  IP1="172.16.17.32" # redis server
  IP2="172.16.31.10" # redis resque server
  FILENAME="/var/lib/redis/6379/testserver_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/testserver_dump_6380.rdb"
fi

if [ "staging" == `hostname` ]; then
  IP1="192.168.3.11" # redis server
  IP2="172.16.58.3" # redis resque server
  FILENAME="/var/lib/redis/6379/staging_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/staging_dump_6380.rdb"
fi

if [ "production"  == `hostname` ]; then
  IP1="88" # redis server
  IP2="88" # redis resque server
  FILENAME="/var/lib/redis/6379/production_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/staging_dump_6380.rdb"
fi

#stop redis on external servers
ssh -t "$SSH_USER@$IP1" "sudo monit stop redis"
ssh -t "$SSH_USER@$IP2" "sudo monit stop redis"

#stop recalc
monit stop recalculate || exit 1

#stop resque
monit stop resque


#factlink uit
monit stop nginx || exit 1

#redis uit (kan dit met monit)
monit stop redis || exit 1
monit stop redis-6380 || exit 1

# scp to external servers
sudo scp "$FILENAME" "$SSH_USER@$IP1:~/dump-6379.rdb" || exit 1
ssh -t "$SSH_USER@$IP1" "sudo mv ~/dump-6379.rdb /var/lib/redis/dump-6379.rdb"
sudo scp "$FILENAME_RESQUE" "$SSH_USER@$IP2:~/dump-6379.rdb" || exit 1
ssh -t "$SSH_USER@$IP2" "sudo mv ~/dump-6379.rdb /var/lib/redis/dump-6379.rdb"

# start redis op external servers
ssh -t "$SSH_USER@$IP1" "sudo monit start redis"
ssh -t "$SSH_USER@$IP2" "sudo monit start redis"

# update config
echo "development:
  redis:
    hostname: localhost
    port: 6381

test:
  redis:
    hostname: localhost
    port: 6379

testserver:
  redis:
    hostname: $IP1
    port: 6379

staging:
  redis:
    hostname: $IP1
    port: 6379

production:
  redis:
    hostname: $IP1
    port: 6379" > '/applications/core/current/config/redis.yml'


echo "development: localhost:6380
test: localhost:6380
testserver: $IP2:6379
staging: $IP2:6379
production: $IP2:6379" > '/applications/core/current/config/resque.yml'

# factlink aan
monit start nginx

# start resque
monit start resque

# start recalc
monit start recalculate<commit_msg>added more debugging info, and wait for servers to shut down<commit_after>#!/usr/bin/env bash
set -e

SSH_USER="jan" # user to ssh to machines with

#ssh jan@testserver.factlink.com "cat /etc/redis/6379.conf | grep dbfilename;ls -d1 /var/lib/redis/6379/*.*;cat /etc/redis/6380.conf | grep dbfilename;ls -d1 /var/lib/redis/6380/*.*;"
if [ "testserver" == `hostname` ]; then
  IP1="172.16.17.32" # redis server
  IP2="172.16.31.10" # redis resque server
  FILENAME="/var/lib/redis/6379/testserver_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/testserver_dump_6380.rdb"
fi

if [ "staging" == `hostname` ]; then
  IP1="192.168.3.11" # redis server
  IP2="172.16.58.3" # redis resque server
  FILENAME="/var/lib/redis/6379/staging_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/staging_dump_6380.rdb"
fi

if [ "production"  == `hostname` ]; then
  IP1="88" # redis server
  IP2="88" # redis resque server
  FILENAME="/var/lib/redis/6379/production_dump.rdb"
  FILENAME_RESQUE="/var/lib/redis/6380/staging_dump_6380.rdb"
fi

echo "stopping remote redis"

ssh -t "$SSH_USER@$IP1" "sudo monit stop redis"
ssh -t "$SSH_USER@$IP2" "sudo monit stop redis"

echo "stopping local services"

#stop recalc
monit stop recalculate || exit 1

#stop resque
monit stop resque


#factlink uit
monit stop nginx || exit 1

#redis uit (kan dit met monit)
monit stop redis || exit 1
monit stop redis-6380 || exit 1

echo "waiting for everything to shut down"
sleep 5

echo "copying redis databases to remote servers"
sudo scp "$FILENAME" "$SSH_USER@$IP1:~/dump-6379.rdb" || exit 1
ssh -t "$SSH_USER@$IP1" "sudo mv ~/dump-6379.rdb /var/lib/redis/dump-6379.rdb"
sudo scp "$FILENAME_RESQUE" "$SSH_USER@$IP2:~/dump-6379.rdb" || exit 1
ssh -t "$SSH_USER@$IP2" "sudo mv ~/dump-6379.rdb /var/lib/redis/dump-6379.rdb"


echo  "start redis op external servers"
ssh -t "$SSH_USER@$IP1" "sudo monit start redis"
ssh -t "$SSH_USER@$IP2" "sudo monit start redis"

echo "updating config"
echo "development:
  redis:
    host: localhost
    port: 6381

test:
  redis:
    host: localhost
    port: 6379

testserver:
  redis:
    host: $IP1
    port: 6379

staging:
  redis:
    host: $IP1
    port: 6379

production:
  redis:
    host: $IP1
    port: 6379" > '/applications/core/current/config/redis.yml'


echo "development: localhost:6380
test: localhost:6380
testserver: $IP2:6379
staging: $IP2:6379
production: $IP2:6379" > '/applications/core/current/config/resque.yml'


echo "restarting services"
# factlink aan
monit start nginx

# start resque
monit start resque

# start recalc
monit start recalculate

echo "Finished"
{'fraction_non_alphanumeric': 0.1415075376884422, 'fraction_numerical': 0.07537688442211055, 'mean_word_length': 4.031344792719919, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 9, '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': '5969954', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2041, 'n_words': 491}