2 Commits

Author SHA1 Message Date
Greg Karékinian
7ce8b7d461 Enable PostgreSQL service 2021-01-23 19:14:55 +01:00
Greg Karékinian
112eb903ec Add a script to switch the primary PostgreSQL server
Usage: scripts/postgresql/switch_primary.sh <old_primary_hostname> <new_primary_hostname>
2021-01-23 19:13:54 +01:00
2 changed files with 20 additions and 1 deletions

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"

View File

@@ -32,7 +32,7 @@ action :create do
service postgresql_service do
supports restart: true, status: true, reload: true
action :start
action [:enable, :start]
end
# This service is a dependency that will auto-start our cluster service on