Skip to content
Open
17 changes: 16 additions & 1 deletion resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@

unless node['postgresql']['registered']
query = {}
query['ID'] = "postgresql-#{node['hostname']}"
service_id = "postgresql-#{node['hostname']}"
query['ID'] = service_id
query['Name'] = 'postgresql'
query['Address'] = ipaddress
query['Port'] = 5432
Expand All @@ -119,6 +120,20 @@
action :nothing
end.run_action(:run)

health_check_json = {
'Name' => 'postgresql-health-check',
'Args' => ['/usr/lib/redborder/bin/rb_check_postgresql.sh'],
'Interval' => '60s',
'Timeout' => '10s',
'Notes' => 'Health check PostgreSQL replication',
'ServiceID' => service_id,
}.to_json

execute 'Register PostgreSQL Consul Health Check' do
command "curl -X PUT http://localhost:8500/v1/agent/check/register -d '#{health_check_json}' &>/dev/null"
action :nothing
end.run_action(:run)

node.normal['postgresql']['registered'] = true
Chef::Log.info('Postgresql service has been registered to consul')
end
Expand Down