Compare commits
2 Commits
7e61e9cb45
...
7ce8b7d461
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ce8b7d461 | ||
|
|
112eb903ec |
19
scripts/postgresql/switch_primary.sh
Executable file
19
scripts/postgresql/switch_primary.sh
Executable 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"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user