Move PostgreSQL to VMs and access via Zerotier #282

Merged
raucao merged 40 commits from feature/postgres_vms into master 2021-01-25 10:56:42 +00:00
Showing only changes of commit 112eb903ec - Show all commits

View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
if [[ $# -ne 2 ]] ; then
echo "Usage: scripts/postgresql/switch_primary.sh <old_primary_hostname> <new_primary_hostname>"
exit 1;
fi
old_primary_hostname=$1
new_primary_hostname=$2
new_primary_ip=`bundle exec knife node show $new_primary_hostname -a knife_zero.host | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" -o`
echo "Switching primary to $new_primary_hostname ($new_primary_ip)"
bundle exec knife ssh name:$new_primary_hostname -a knife_zero.host "sudo su - postgres -c '/usr/lib/postgresql/12/bin/pg_ctl promote -D /var/lib/postgresql/12/main'"
echo "Replacing pg.kosmos.local host entries with $new_primary_ip"
bundle exec knife ssh roles:postgresql_client -a knife_zero.host "sudo sed -r \"s/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s(pg.kosmos.local)/$new_primary_ip\t\1/\" -i /etc/hosts"
echo "Stopping postgresql on $old_primary_hostname"
bundle exec knife ssh name:$old_primary_hostname -a knife_zero.host "sudo systemctl stop postgresql@12-main.service"