Skip to content

Commit

Permalink
rb_keepalived_master_notify_postgresql.sh is exectued each time keepa…
Browse files Browse the repository at this point in the history
…lived.conf is changed
  • Loading branch information
rgomezborder committed Oct 14, 2024
1 parent e91284f commit 404d20f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
retries 2
variables(vip: virtual_ips['internal']['postgresql']['ip'], iface: virtual_ips['internal']['postgresql']['iface'])
end

execute 'notify_master_postgresql' do
command '/usr/lib/redborder/bin/rb_keepalived_master_notify_postgresql.sh'
action :nothing
end
end

template '/etc/keepalived/keepalived.conf' do
Expand All @@ -91,6 +96,7 @@
group 'root'
mode '0644'
retries 2
notifies :run, 'execute[notify_master_postgresql]', :immediately
notifies :reload, 'service[keepalived]'
variables(vrrp_password: vrrp_secrets['pass'], managers: managers, start_id: vrrp_secrets['start_id'], balanced_services: balanced_services, virtual_ips: virtual_ips, virtual_ips_per_ip: virtual_ips_per_ip, has_any_virtual_ip: has_any_virtual_ip, manager_services: manager_services, ipmgt: ipmgt, iface: iface, ipsync: ipaddress_sync, managers_per_service: managers_per_service)
end
Expand Down
9 changes: 5 additions & 4 deletions resources/templates/default/notify_postgresql.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ else
fi

IS_RECOVERY=$(sudo -u postgres psql -h 127.0.0.1 -t -c "SELECT pg_is_in_recovery();" 2>/dev/null | tr -d ' \t\n\r')
MASTER_NAME=$(serf members | grep 'postgresql=ready' | awk '{print $1}')
MASTER_NAME=$(serf members | grep 'postgresql_role=master' | awk '{print $1}')
CURRENT_NODE=$(hostname -s)

if [ "$IS_RECOVERY" == "t" ]; then
if [ "x$IS_RECOVERY" == "xt" ]; then
echo "The database is in recovery mode (Read-Only) on $CURRENT_NODE."

if [ -z "$MASTER_NAME" ]; then
Expand All @@ -66,6 +66,7 @@ else
echo "The database is not in recovery mode (Read-Write) on $CURRENT_NODE."
fi

echo "Updating /etc/hosts"
sed -i 's/.*postgresql.*//g' /etc/hosts
echo "$IP_VIRTUAL master.postgresql.service" >> /etc/hosts
rbcli service stop redborder-postgresql
sudo sed -i '/^$/d' /etc/hosts
echo "$IP_VIRTUAL master.postgresql.service" >> /etc/hosts

0 comments on commit 404d20f

Please sign in to comment.