Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions chef/cookbooks/postgresql/recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,57 @@

change_notify = node["postgresql"]["server"]["config_change_notify"]

raw_configuration = node["postgresql"]["config"]
postgresql_configuration = {}
raw_configuration.each do |key, value|
next if value.nil?
formatted_value = case value
when String
"'#{value}'"
when TrueClass
"on"
when FalseClass
"off"
else
value
end
postgresql_configuration[key] = formatted_value
end

reloadable_parameters = [
"log_line_prefix"
]

config_needs_restart = postgresql_configuration.reject do |key, value|
reloadable_parameters.include? key
end

config_needs_reload = postgresql_configuration.select do |key, value|
reloadable_parameters.include? key
end

template "#{node['postgresql']['dir']}/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
group "postgres"
mode 0600
variables(
config: config_needs_restart.sort
)
notifies change_notify, "service[postgresql]", :immediately
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing an issue for me, it seems that this causes the service to be immediately reloaded after the template change, but before the postgresql_reloadable.conf exists, so postgresql fails due to a syntax error because the incuded file doesn't exist yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that could be true indeed. I did not run into that trouble, as the HA restart was still broken on my branch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happened to be checking it in non-ha mode.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add a fix for that.

end

template "#{node['postgresql']['dir']}/postgresql_reloadable.conf" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)

source "postgresql_reloadable.conf.erb"
owner "postgres"
group "postgres"
mode "0600"
variables(
config: config_needs_reload.sort
)
notifies :run, "bash[reload-postgresql-configuration]", :immediately
end

template "#{node['postgresql']['dir']}/pg_hba.conf" do
source "pg_hba.conf.erb"
owner "postgres"
Expand Down Expand Up @@ -164,3 +207,16 @@
only_if only_if_command if ha_enabled
action :run
end

# Reload the configuration file
# We use the SQL interface for that. This way it will work
# in clustered mode as well, no matter which node runs it
# first
bash "reload-postgresql-configuration" do
user "postgres"
code <<-EOH
echo "SELECT pg_reload_conf();" | psql
EOH
action :nothing
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingBlankLines: 1 trailing blank lines detected. (https://github.com/bbatsov/ruby-style-guide#newline-eof)

18 changes: 4 additions & 14 deletions chef/cookbooks/postgresql/templates/default/postgresql.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
# Please refer to the PostgreSQL documentation for details on
# configuration settings.

<% node['postgresql']['config'].sort.each do |key, value| %>
<% next if value.nil? -%>
<%= key %> = <%=
case value
when String
"'#{value}'"
when TrueClass
'on'
when FalseClass
'off'
else
value
end
%>
include 'postgresql_reloadable.conf'

<% @config.each do |key, value| %>
<%= key %> = <%= value %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @config.each do |key, value| %>
<%= key %> = <%= value %>
<% end %>