diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 3ff3f15..e87c54e 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -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 @@ -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