Skip to content

Commit

Permalink
check nodes list size
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsver committed Aug 30, 2024
1 parent d5e4a64 commit fe7a498
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@
# Check if postgresql is registered to delete postgresql in /etc/hosts
consul_response = `curl #{node['ipaddress']}:8500/v1/catalog/services 2>/dev/null | jq .postgresql`
postgresql_registered = (consul_response == 'null\n' || consul_response == '') ? false : true
if postgresql_registered
# Postgres should be added to /etc/hosts when there is only 1 node
server_members = `serf members -format=json`
postgresql_nodes = JSON.parse(server_members) unless server_members.strip.empty?
if postgresql_registered && postgresql_nodes && postgresql_nodes.size > 1
execute 'Removing postgresql service from /etc/hosts' do
command "sed -i 's/.*postgresql.*//g' /etc/hosts"
end
Expand Down

0 comments on commit fe7a498

Please sign in to comment.