Set up an instance of Mastodon for Kosmos

Refs #19

Use new application cookbook, update our cookbooks
This commit is contained in:
Greg Karékinian
2017-04-06 21:20:51 +02:00
parent a3f5c5f646
commit de11c0d691
345 changed files with 22591 additions and 3473 deletions

View File

@@ -1,14 +1,4 @@
if not %w(jessie squeeze wheezy sid lucid precise saucy trusty utopic).include? node['postgresql']['pgdg']['release_apt_codename']
raise "Not supported release by PGDG apt repository"
end
include_recipe 'apt'
file "remove deprecated Pitti PPA apt repository" do
action :delete
path "/etc/apt/sources.list.d/pitti-postgresql-ppa"
end
# frozen_string_literal: true
apt_repository 'apt.postgresql.org' do
uri 'http://apt.postgresql.org/pub/repos/apt'
distribution "#{node['postgresql']['pgdg']['release_apt_codename']}-pgdg"

View File

@@ -1,6 +1,2 @@
# some older linux distributions have expired certificate bundles
# for pgdg repositories. Upgrading this package before trying to
# install postgresql is necessary.
package "ca-certificates" do
action :upgrade
end
# frozen_string_literal: true
Chef::Log.warn('The postgresql::ca-certificates recipe has been deprecated and will be removed in the next major release of the cookbook')

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: client
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,23 +16,19 @@
# limitations under the License.
#
include_recipe "postgresql::ca_certificates"
case node['platform_family']
when 'debian'
if node['postgresql']['version'].to_f > 9.3
node.set['postgresql']['enable_pgdg_apt'] = true
node.normal['postgresql']['enable_pgdg_apt'] = true
end
if node['postgresql']['enable_pgdg_apt']
include_recipe 'postgresql::apt_pgdg_postgresql'
end
when 'rhel'
when 'rhel', 'fedora'
if node['postgresql']['enable_pgdg_yum']
include_recipe 'postgresql::yum_pgdg_postgresql'
end
end
node['postgresql']['client']['packages'].each do |pkg|
package pkg
end
package node['postgresql']['client']['packages']

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: config_initdb
# Author:: David Crane (<davidc@donorschoose.org>)
#
@@ -69,23 +70,23 @@
# Locale Configuration
# See libraries/default.rb for the locale_date_order() method.
node.default['postgresql']['config']['datestyle'] = "iso, #{locale_date_order()}"
node.default['postgresql']['config']['datestyle'] = "iso, #{locale_date_order}"
# According to the locale(1) manpage, the locale settings are determined
# by environment variables according to the following precedence:
# LC_ALL > (LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) > LANG.
node.default['postgresql']['config']['lc_messages'] =
[ ENV['LC_ALL'], ENV['LC_MESSAGES'], ENV['LANG'] ].compact.first
[ENV['LC_ALL'], ENV['LC_MESSAGES'], ENV['LANG']].compact.first
node.default['postgresql']['config']['lc_monetary'] =
[ ENV['LC_ALL'], ENV['LC_MONETARY'], ENV['LANG'] ].compact.first
[ENV['LC_ALL'], ENV['LC_MONETARY'], ENV['LANG']].compact.first
node.default['postgresql']['config']['lc_numeric'] =
[ ENV['LC_ALL'], ENV['LC_NUMERIC'], ENV['LANG'] ].compact.first
[ENV['LC_ALL'], ENV['LC_NUMERIC'], ENV['LANG']].compact.first
node.default['postgresql']['config']['lc_time'] =
[ ENV['LC_ALL'], ENV['LC_TIME'], ENV['LANG'] ].compact.first
[ENV['LC_ALL'], ENV['LC_TIME'], ENV['LANG']].compact.first
node.default['postgresql']['config']['default_text_search_config'] =
case ENV['LANG']
@@ -119,8 +120,6 @@ node.default['postgresql']['config']['default_text_search_config'] =
'pg_catalog.swedish'
when /tr_.*/
'pg_catalog.turkish'
else
nil
end
#######
@@ -130,11 +129,11 @@ node.default['postgresql']['config']['default_text_search_config'] =
# defaults for the postgresql.cof settings. If the timezone cannot be
# identified, do as initdb would do: leave it unspecified so PostgreSQL
# uses it's internal default of GMT.
tzdirpath = pg_TZDIR() # See libraries/default.rb
tzdirpath = pg_TZDIR # See libraries/default.rb
default_timezone = select_default_timezone(tzdirpath) # See libraries/default.rb
if !default_timezone.nil?
node.default['postgresql']['config']['log_timezone'] = default_timezone
node.default['postgresql']['config']['timezone'] = default_timezone
unless default_timezone.nil?
node.default['postgresql']['config']['log_timezone'] = default_timezone
node.default['postgresql']['config']['timezone'] = default_timezone
end
#######

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: config_pgtune
# Author:: David Crane (<davidc@donorschoose.org>)
#
@@ -86,35 +87,35 @@
# Parse out db_type option, or use default.
db_type = 'mixed'
if (node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('db_type'))
if node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('db_type')
db_type = node['postgresql']['config_pgtune']['db_type']
if (!(["dw","oltp","web","mixed","desktop"].include?(db_type)))
unless %w(dw oltp web mixed desktop).include?(db_type)
Chef::Log.fatal([
"Bad value (#{db_type})",
"for node['postgresql']['config_pgtune']['db_type'] attribute.",
"Valid values are one of dw, oltp, web, mixed, desktop."
].join(' '))
"Bad value (#{db_type})",
"for node['postgresql']['config_pgtune']['db_type'] attribute.",
'Valid values are one of dw, oltp, web, mixed, desktop.',
].join(' '))
raise
end
end
# Parse out max_connections option, or use a value based on db_type.
con =
{ "web" => 200,
"oltp" => 300,
"dw" => 20,
"mixed" => 80,
"desktop" => 5
}.fetch(db_type)
{ 'web' => 200,
'oltp' => 300,
'dw' => 20,
'mixed' => 80,
'desktop' => 5,
}.fetch(db_type)
if (node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('max_connections'))
if node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('max_connections')
max_connections = node['postgresql']['config_pgtune']['max_connections'].to_i
if max_connections <= 0
Chef::Log.fatal([
"Bad value (#{max_connections})",
"for node['postgresql']['config_pgtune']['max_connections'] attribute.",
"Valid values are non-zero integers only."
].join(' '))
"Bad value (#{max_connections})",
"for node['postgresql']['config_pgtune']['max_connections'] attribute.",
'Valid values are non-zero integers only.',
].join(' '))
raise
end
con = max_connections
@@ -125,19 +126,19 @@ total_memory = node['memory']['total']
# Override max_connections with a node attribute if DevOps desires.
# For example, on a system *not* dedicated to Postgresql.
if (node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('total_memory'))
if node['postgresql'].attribute?('config_pgtune') && node['postgresql']['config_pgtune'].attribute?('total_memory')
total_memory = node['postgresql']['config_pgtune']['total_memory']
if (total_memory.match(/\A[1-9]\d*kB\Z/) == nil)
if total_memory.match(/\A[1-9]\d*kB\Z/).nil?
Chef::Application.fatal!([
"Bad value (#{total_memory})",
"for node['postgresql']['config_pgtune']['total_memory'] attribute.",
"Valid values are non-zero integers followed by kB (e.g., 49416564kB)."
].join(' '))
"Bad value (#{total_memory})",
"for node['postgresql']['config_pgtune']['total_memory'] attribute.",
'Valid values are non-zero integers followed by kB (e.g., 49416564kB).',
].join(' '))
end
end
# Ohai reports node[:memory][:total] in kB, as in "921756kB"
mem = total_memory.split("kB")[0].to_i / 1024 # in MB
mem = total_memory.split('kB')[0].to_i / 1024 # in MB
#######
# RAM-related settings computed as in Greg Smith's pgtune script.
@@ -152,79 +153,73 @@ node.default['postgresql']['config']['max_connections'] = con
# for low memory systems. In that case, the calculation is skipped,
# leaving the built-in Postgresql settings, which are actually
# intended for those low memory systems.
if (mem >= 256)
if mem >= 256
# (2) shared_buffers
# Sets the number of shared memory buffers used by the server.
shared_buffers =
{ "web" => mem/4,
"oltp" => mem/4,
"dw" => mem/4,
"mixed" => mem/4,
"desktop" => mem/16
}.fetch(db_type)
{ 'web' => mem / 4,
'oltp' => mem / 4,
'dw' => mem / 4,
'mixed' => mem / 4,
'desktop' => mem / 16,
}.fetch(db_type)
# Robert Haas has advised to cap the size of shared_buffers based on
# the memory architecture: 2GB on 32-bit and 8GB on 64-bit machines.
# http://rhaas.blogspot.com/2012/03/tuning-sharedbuffers-and-walbuffers.html
case node['kernel']['machine']
when "i386" # 32-bit machines
if shared_buffers > 2*1024
shared_buffers = 2*1024
end
when "x86_64" # 64-bit machines
if shared_buffers > 8*1024
shared_buffers = 8*1024
end
when 'i386' # 32-bit machines
shared_buffers = 2 * 1024 if shared_buffers > 2 * 1024
when 'x86_64' # 64-bit machines
shared_buffers = 8 * 1024 if shared_buffers > 8 * 1024
end
node.default['postgresql']['config']['shared_buffers'] = binaryround(shared_buffers*1024*1024)
node.default['postgresql']['config']['shared_buffers'] = binaryround(shared_buffers * 1024 * 1024)
# (3) effective_cache_size
# Sets the planner's assumption about the size of the disk cache.
# That is, the portion of the kernel's disk cache that will be
# used for PostgreSQL data files.
effective_cache_size =
{ "web" => mem * 3 / 4,
"oltp" => mem * 3 / 4,
"dw" => mem * 3 / 4,
"mixed" => mem * 3 / 4,
"desktop" => mem / 4
}.fetch(db_type)
{ 'web' => mem * 3 / 4,
'oltp' => mem * 3 / 4,
'dw' => mem * 3 / 4,
'mixed' => mem * 3 / 4,
'desktop' => mem / 4,
}.fetch(db_type)
node.default['postgresql']['config']['effective_cache_size'] = binaryround(effective_cache_size*1024*1024)
node.default['postgresql']['config']['effective_cache_size'] = binaryround(effective_cache_size * 1024 * 1024)
# (4) work_mem
# Sets the maximum memory to be used for query workspaces.
mem_con_v = (mem.to_f / con).ceil
work_mem =
{ "web" => mem_con_v,
"oltp" => mem_con_v,
"dw" => mem_con_v / 2,
"mixed" => mem_con_v / 2,
"desktop" => mem_con_v / 6
{ 'web' => mem_con_v,
'oltp' => mem_con_v,
'dw' => mem_con_v / 2,
'mixed' => mem_con_v / 2,
'desktop' => mem_con_v / 6,
}.fetch(db_type)
node.default['postgresql']['config']['work_mem'] = binaryround(work_mem*1024*1024)
node.default['postgresql']['config']['work_mem'] = binaryround(work_mem * 1024 * 1024)
# (5) maintenance_work_mem
# Sets the maximum memory to be used for maintenance operations.
# This includes operations such as VACUUM and CREATE INDEX.
maintenance_work_mem =
{ "web" => mem / 16,
"oltp" => mem / 16,
"dw" => mem / 8,
"mixed" => mem / 16,
"desktop" => mem / 16
}.fetch(db_type)
{ 'web' => mem / 16,
'oltp' => mem / 16,
'dw' => mem / 8,
'mixed' => mem / 16,
'desktop' => mem / 16,
}.fetch(db_type)
# Cap maintenence RAM at 1GB on servers with lots of memory
if (maintenance_work_mem > 1*1024)
maintenance_work_mem = 1*1024
end
maintenance_work_mem = 1 * 1024 if maintenance_work_mem > 1 * 1024
node.default['postgresql']['config']['maintenance_work_mem'] = binaryround(maintenance_work_mem*1024*1024)
node.default['postgresql']['config']['maintenance_work_mem'] = binaryround(maintenance_work_mem * 1024 * 1024)
end
@@ -235,25 +230,29 @@ end
# (6) checkpoint_segments
# Sets the maximum distance in log segments between automatic WAL checkpoints.
checkpoint_segments =
{ "web" => 8,
"oltp" => 16,
"dw" => 64,
"mixed" => 16,
"desktop" => 3
}.fetch(db_type)
{ 'web' => 8,
'oltp' => 16,
'dw' => 64,
'mixed' => 16,
'desktop' => 3,
}.fetch(db_type)
node.default['postgresql']['config']['checkpoint_segments'] = checkpoint_segments
if node['postgresql']['version'].to_f >= 9.5
node.default['postgresql']['config']['max_wal_size'] = ((3 * checkpoint_segments) * 16).to_s + 'MB'
else
node.default['postgresql']['config']['checkpoint_segments'] = checkpoint_segments
end
# (7) checkpoint_completion_target
# Time spent flushing dirty buffers during checkpoint, as fraction
# of checkpoint interval.
checkpoint_completion_target =
{ "web" => "0.7",
"oltp" => "0.9",
"dw" => "0.9",
"mixed" => "0.9",
"desktop" => "0.5"
}.fetch(db_type)
{ 'web' => '0.7',
'oltp' => '0.9',
'dw' => '0.9',
'mixed' => '0.9',
'desktop' => '0.5',
}.fetch(db_type)
node.default['postgresql']['config']['checkpoint_completion_target'] = checkpoint_completion_target
@@ -264,9 +263,9 @@ node.default['postgresql']['config']['checkpoint_completion_target'] = checkpoin
if node['postgresql']['version'].to_f < 9.1
wal_buffers = 512 * checkpoint_segments
# The pgtune seems to use 1kB units for wal_buffers
node.default['postgresql']['config']['wal_buffers'] = binaryround(wal_buffers*1024)
node.default['postgresql']['config']['wal_buffers'] = binaryround(wal_buffers * 1024)
else
node.default['postgresql']['config']['wal_buffers'] = "-1"
node.default['postgresql']['config']['wal_buffers'] = '-1'
end
# (9) default_statistics_target
@@ -274,11 +273,11 @@ end
# that have not had a column-specific target set via
# ALTER TABLE SET STATISTICS.
default_statistics_target =
{ "web" => 100,
"oltp" => 100,
"dw" => 500,
"mixed" => 100,
"desktop" => 100
}.fetch(db_type)
{ 'web' => 100,
'oltp' => 100,
'dw' => 500,
'mixed' => 100,
'desktop' => 100,
}.fetch(db_type)
node.default['postgresql']['config']['default_statistics_target'] = default_statistics_target

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: contrib
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,26 +20,14 @@ db_name = node['postgresql']['database_name']
# Install the PostgreSQL contrib package(s) from the distribution,
# as specified by the node attributes.
node['postgresql']['contrib']['packages'].each do |pg_pack|
package node['postgresql']['contrib']['packages']
package pg_pack
end
include_recipe "postgresql::server"
include_recipe 'postgresql::server'
# Install PostgreSQL contrib extentions into the database, as specified by the
# node attribute node['postgresql']['database_name'].
if (node['postgresql']['contrib'].attribute?('extensions'))
if node['postgresql']['contrib'].attribute?('extensions')
node['postgresql']['contrib']['extensions'].each do |pg_ext|
bash "install-#{pg_ext}-extension" do
user 'postgres'
code <<-EOH
echo 'CREATE EXTENSION IF NOT EXISTS "#{pg_ext}";' | psql -d "#{db_name}"
EOH
action :run
::Chef::Resource.send(:include, Opscode::PostgresqlHelpers)
not_if {extension_installed?(pg_ext)}
end
postgresql_extension "#{db_name}/#{pg_ext}"
end
end

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: default
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,4 +16,4 @@
# limitations under the License.
#
include_recipe "postgresql::client"
include_recipe 'postgresql::client'

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: false
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: ruby
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,70 +22,51 @@
begin
require 'pg'
rescue LoadError
if platform_family?('ubuntu', 'debian')
e = execute 'apt-get update' do
if platform_family?('debian')
e = apt_update 'update' do
action :nothing
end
e.run_action(:run) unless ::File.exists?('/var/lib/apt/periodic/update-success-stamp')
e.run_action(:update)
end
node.set['build-essential']['compile_time'] = true
include_recipe "build-essential"
node.override['build-essential']['compile_time'] = true
include_recipe 'build-essential'
if node['postgresql']['enable_pgdg_yum']
package "ca-certificates" do
action :nothing
end.run_action(:upgrade)
include_recipe "postgresql::yum_pgdg_postgresql"
if node['postgresql']['enable_pgdg_yum'] && platform_family?('rhel', 'fedora')
include_recipe 'postgresql::yum_pgdg_postgresql'
rpm_platform = node['platform']
rpm_platform_version = node['platform_version'].to_f.to_i.to_s
rpm_platform_version = node['platform_version'].to_i.to_s
arch = node['kernel']['machine']
resources("remote_file[#{Chef::Config[:file_cache_path]}/#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}]").run_action(:create)
resources("package[#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}]").run_action(:install)
resources("remote_file[#{Chef::Config[:file_cache_path]}/#{node['postgresql']['pgdg']['repo_rpm_url'][node['postgresql']['version']][rpm_platform][rpm_platform_version][arch]['package']}]").run_action(:create)
resources("package[#{node['postgresql']['pgdg']['repo_rpm_url'][node['postgresql']['version']][rpm_platform][rpm_platform_version][arch]['package']}]").run_action(:install)
ENV['PATH'] = "/usr/pgsql-#{node['postgresql']['version']}/bin:#{ENV['PATH']}"
node['postgresql']['client']['packages'].each do |pkg|
package pkg do
action :nothing
end.run_action(:install)
end
end
if node['postgresql']['enable_pgdg_apt']
include_recipe "postgresql::apt_pgdg_postgresql"
resources("file[remove deprecated Pitti PPA apt repository]").run_action(:delete)
resources("apt_repository[apt.postgresql.org]").run_action(:add)
node['postgresql']['client']['packages'].each do |pkg|
package pkg do
action :nothing
end.run_action(:install)
end
if node['postgresql']['enable_pgdg_apt'] && platform_family?('debian')
include_recipe 'postgresql::apt_pgdg_postgresql'
resources('apt_repository[apt.postgresql.org]').run_action(:add)
end
include_recipe "postgresql::client"
include_recipe 'postgresql::client'
node['postgresql']['client']['packages'].each do |pkg|
package pkg do
action :nothing
end.run_action(:install)
end
package node['postgresql']['client']['packages'] do
action :nothing
end.run_action(:install)
begin
chef_gem "pg"
chef_gem 'pg' do
compile_time true
version node['postgresql']['pg_gem']['version'] if node['postgresql']['pg_gem']['version']
end
rescue Gem::Installer::ExtensionBuildError, Mixlib::ShellOut::ShellCommandFailed => e
# Are we an omnibus install?
raise if RbConfig.ruby.scan(%r{(chef|opscode)}).empty?
raise if RbConfig.ruby.scan(/(chef|opscode)/).empty?
# Still here, must be omnibus. Lets make this thing install!
Chef::Log.warn 'Failed to properly build pg gem. Forcing properly linking and retrying (omnibus fix)'
gem_dir = e.message.scan(%r{will remain installed in ([^ ]+)}).flatten.first
gem_dir = e.message.scan(/will remain installed in ([^ ]+)/).flatten.first
raise unless gem_dir
gem_name = File.basename(gem_dir)
ext_dir = File.join(gem_dir, 'ext')

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: server
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,25 +16,23 @@
# limitations under the License.
#
include_recipe "postgresql::ca_certificates"
::Chef::Recipe.send(:include, OpenSSLCookbook::RandomPassword)
include_recipe "postgresql::client"
include_recipe 'postgresql::client'
# randomly generate postgres password, unless using solo - see README
if Chef::Config[:solo]
missing_attrs = %w{
missing_attrs = %w(
postgres
}.select do |attr|
).select do |attr|
node['postgresql']['password'][attr].nil?
end.map { |attr| "node['postgresql']['password']['#{attr}']" }
if !missing_attrs.empty?
unless missing_attrs.empty?
Chef::Log.fatal([
"You must set #{missing_attrs.join(', ')} in chef-solo mode.",
"For more information, see https://github.com/opscode-cookbooks/postgresql#chef-solo-note"
].join(' '))
"You must set #{missing_attrs.join(', ')} in chef-solo mode.",
'For more information, see https://github.com/opscode-cookbooks/postgresql#chef-solo-note',
].join(' '))
raise
end
else
@@ -44,7 +43,7 @@ else
# useful if it weren't saved as clear text in Chef Server for later
# retrieval.
unless node.key?('postgresql') && node['postgresql'].key?('password') && node['postgresql']['password'].key?('postgres')
node.set_unless['postgresql']['password']['postgres'] = random_password(length: 20, mode: :base64)
node.normal_unless['postgresql']['password']['postgres'] = random_password(length: 20, mode: :base64)
node.save
end
end
@@ -52,30 +51,29 @@ end
# Include the right "family" recipe for installing the server
# since they do things slightly differently.
case node['platform_family']
when "rhel", "fedora"
node.set['postgresql']['dir'] = "/var/lib/pgsql/#{node['postgresql']['version']}/data"
node.set['postgresql']['config']['data_directory'] = "/var/lib/pgsql/#{node['postgresql']['version']}/data"
include_recipe "postgresql::server_redhat"
when "debian"
node.set['postgresql']['config']['data_directory'] = "/var/lib/postgresql/#{node['postgresql']['version']}/main"
include_recipe "postgresql::server_debian"
when 'rhel', 'fedora'
node.normal['postgresql']['dir'] = "/var/lib/pgsql/#{node['postgresql']['version']}/data"
node.normal['postgresql']['config']['data_directory'] = "/var/lib/pgsql/#{node['postgresql']['version']}/data"
include_recipe 'postgresql::server_redhat'
when 'debian'
node.normal['postgresql']['config']['data_directory'] = "/var/lib/postgresql/#{node['postgresql']['version']}/main"
include_recipe 'postgresql::server_debian'
when 'suse'
node.set['postgresql']['config']['data_directory'] = node['postgresql']['dir']
include_recipe "postgresql::server_redhat"
node.normal['postgresql']['config']['data_directory'] = node['postgresql']['dir']
include_recipe 'postgresql::server_redhat'
end
# Versions prior to 9.2 do not have a config file option to set the SSL
# key and cert path, and instead expect them to be in a specific location.
if node['postgresql']['version'].to_f < 9.2 && node['postgresql']['config'].attribute?('ssl_cert_file')
link ::File.join(node['postgresql']['config']['data_directory'], 'server.crt') do
to node['postgresql']['config']['ssl_cert_file']
end
link ::File.join(node['postgresql']['config']['data_directory'], 'server.crt') do
to node['postgresql']['config']['ssl_cert_file']
only_if { node['postgresql']['version'].to_f < 9.2 && node['postgresql']['config'].attribute?('ssl_cert_file') }
end
if node['postgresql']['version'].to_f < 9.2 && node['postgresql']['config'].attribute?('ssl_key_file')
link ::File.join(node['postgresql']['config']['data_directory'], 'server.key') do
to node['postgresql']['config']['ssl_key_file']
end
link ::File.join(node['postgresql']['config']['data_directory'], 'server.key') do
to node['postgresql']['config']['ssl_key_file']
only_if { node['postgresql']['version'].to_f < 9.2 && node['postgresql']['config'].attribute?('ssl_key_file') }
end
# NOTE: Consider two facts before modifying "assign-postgres-password":
@@ -86,7 +84,7 @@ end
# setting the same password. This chef recipe doesn't have access to
# the plain text password, and testing the encrypted (md5 digest)
# version is not straight-forward.
bash "assign-postgres-password" do
bash 'assign-postgres-password' do
user 'postgres'
code <<-EOH
echo "ALTER ROLE postgres ENCRYPTED PASSWORD \'#{node['postgresql']['password']['postgres']}\';" | psql -p #{node['postgresql']['config']['port']}

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: server
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,37 +21,35 @@ change_notify = node['postgresql']['server']['config_change_notify']
# There are some configuration items which depend on correctly evaluating the intended version being installed
if node['platform_family'] == 'debian'
node.set['postgresql']['config']['hba_file'] = "/etc/postgresql/#{node['postgresql']['version']}/main/pg_hba.conf"
node.set['postgresql']['config']['ident_file'] = "/etc/postgresql/#{node['postgresql']['version']}/main/pg_ident.conf"
node.set['postgresql']['config']['external_pid_file'] = "/var/run/postgresql/#{node['postgresql']['version']}-main.pid"
node.normal['postgresql']['config']['hba_file'] = "/etc/postgresql/#{node['postgresql']['version']}/main/pg_hba.conf"
node.normal['postgresql']['config']['ident_file'] = "/etc/postgresql/#{node['postgresql']['version']}/main/pg_ident.conf"
node.normal['postgresql']['config']['external_pid_file'] = "/var/run/postgresql/#{node['postgresql']['version']}-main.pid"
if node['postgresql']['version'].to_f < 9.3
node.set['postgresql']['config']['unix_socket_directory'] = '/var/run/postgresql'
node.normal['postgresql']['config']['unix_socket_directory'] = '/var/run/postgresql'
else
node.set['postgresql']['config']['unix_socket_directories'] = '/var/run/postgresql'
node.normal['postgresql']['config']['unix_socket_directories'] = '/var/run/postgresql'
end
node.set['postgresql']['config']['max_fsm_pages'] = 153600 if node['postgresql']['version'].to_f < 8.4
if node['postgresql']['config']['ssl']
node.set['postgresql']['config']['ssl_cert_file'] = '/etc/ssl/certs/ssl-cert-snakeoil.pem' if node['postgresql']['version'].to_f >= 9.2
node.set['postgresql']['config']['ssl_key_file'] = '/etc/ssl/private/ssl-cert-snakeoil.key'if node['postgresql']['version'].to_f >= 9.2
node.normal['postgresql']['config']['ssl_cert_file'] = '/etc/ssl/certs/ssl-cert-snakeoil.pem' if node['postgresql']['version'].to_f >= 9.2
node.normal['postgresql']['config']['ssl_key_file'] = '/etc/ssl/private/ssl-cert-snakeoil.key' if node['postgresql']['version'].to_f >= 9.2
end
end
template "#{node['postgresql']['dir']}/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
group "postgres"
mode 0600
source 'postgresql.conf.erb'
owner 'postgres'
group 'postgres'
mode '0600'
notifies change_notify, 'service[postgresql]', :immediately
end
template "#{node['postgresql']['dir']}/pg_hba.conf" do
source "pg_hba.conf.erb"
owner "postgres"
group "postgres"
mode 00600
source 'pg_hba.conf.erb'
owner 'postgres'
group 'postgres'
mode '0600'
notifies change_notify, 'service[postgresql]', :immediately
end

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: server
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,19 +16,15 @@
# limitations under the License.
#
include_recipe "postgresql::client"
include_recipe 'postgresql::client'
node['postgresql']['server']['packages'].each do |pg_pack|
package node['postgresql']['server']['packages']
package pg_pack
include_recipe 'postgresql::server_conf'
end
include_recipe "postgresql::server_conf"
service "postgresql" do
service 'postgresql' do
service_name node['postgresql']['server']['service_name']
supports :restart => true, :status => true, :reload => true
supports restart: true, status: true, reload: true
action [:enable, :start]
end

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe:: server
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +16,7 @@
# limitations under the License.
#
include_recipe "postgresql::client"
include_recipe 'postgresql::client'
svc_name = node['postgresql']['server']['service_name']
initdb_locale = node['postgresql']['initdb_locale']
@@ -25,44 +26,39 @@ shortver = node['postgresql']['version'].split('.').join
# Create a group and user like the package will.
# Otherwise the templates fail.
group "postgres" do
gid 26
group 'postgres' do
gid node['postgresql']['gid']
end
user "postgres" do
shell "/bin/bash"
comment "PostgreSQL Server"
home "/var/lib/pgsql"
gid "postgres"
user 'postgres' do
shell '/bin/bash'
comment 'PostgreSQL Server'
home '/var/lib/pgsql'
gid 'postgres'
system true
uid 26
supports :manage_home => false
uid node['postgresql']['uid']
manage_home false
end
directory node['postgresql']['config']['data_directory'] do
owner "postgres"
group "postgres"
owner 'postgres'
group 'postgres'
recursive true
action :create
mode '0700'
end
node['postgresql']['server']['packages'].each do |pg_pack|
package pg_pack
end
package node['postgresql']['server']['packages']
# If using PGDG, add symlinks so that downstream commands all work
if node['postgresql']['enable_pgdg_yum'] == true
if node['postgresql']['enable_pgdg_yum'] == true || node['postgresql']['use_pgdg_packages'] == true
[
"postgresql#{shortver}-setup",
"postgresql#{shortver}-check-db-dir"
"postgresql#{shortver}-check-db-dir",
].each do |cmd|
link "/usr/bin/#{cmd}" do
to "/usr/pgsql-#{node['postgresql']['version']}/bin/#{cmd}"
end
end
end
@@ -71,22 +67,44 @@ end
unless node['postgresql']['server']['init_package'] == 'systemd'
directory "/etc/sysconfig/pgsql" do
mode "0644"
directory '/etc/sysconfig/pgsql' do
mode '0644'
recursive true
action :create
end
template "/etc/sysconfig/pgsql/#{svc_name}" do
source "pgsql.sysconfig.erb"
mode "0644"
notifies :restart, "service[postgresql]", :delayed
source 'pgsql.sysconfig.erb'
mode '0644'
notifies :restart, 'service[postgresql]', :delayed
end
end
if node['postgresql']['server']['init_package'] == 'systemd'
if node['platform_family'] == 'rhel'
template_path = if node['postgresql']['use_pgdg_packages']
"/etc/systemd/system/postgresql-#{node['postgresql']['version']}.service"
else
'/etc/systemd/system/postgresql.service'
end
template template_path do
source 'postgresql.service.erb'
owner 'root'
group 'root'
mode '0644'
notifies :run, 'execute[systemctl-reload]', :immediately
notifies :reload, 'service[postgresql]', :delayed
end
execute 'systemctl-reload' do
command 'systemctl daemon-reload'
action :nothing
end
end
case node['platform_family']
when 'suse'
execute "initdb -d #{node['postgresql']['dir']}" do
@@ -99,7 +117,7 @@ if node['postgresql']['server']['init_package'] == 'systemd'
end
end
elsif (!platform_family?("suse") && node['postgresql']['version'].to_f <= 9.3)
elsif !platform_family?('suse') && node['postgresql']['version'].to_f <= 9.3
execute "/sbin/service #{svc_name} initdb #{initdb_locale}" do
not_if { ::File.exist?("#{node['postgresql']['config']['data_directory']}/PG_VERSION") }
@@ -113,10 +131,10 @@ else
end
service "postgresql" do
service 'postgresql' do
service_name svc_name
supports :restart => true, :status => true, :reload => true
supports restart: true, status: true, reload: true
action [:enable, :start]
end
include_recipe "postgresql::server_conf"
include_recipe 'postgresql::server_conf'

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true
#
# Cookbook Name:: postgresql
# Cookbook:: postgresql
# Recipe::yum_pgdg_postgresql
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,16 +22,20 @@
rpm_platform = node['platform']
rpm_platform_version = node['platform_version'].to_f.to_i.to_s
arch = node['kernel']['machine']
pg_version = node['postgresql']['version']
pgdg_setup = node['postgresql']['pgdg']['repo_rpm_url'][pg_version][rpm_platform][rpm_platform_version][arch]
pgdg_package = pgdg_setup['package']
pgdg_repository = pgdg_setup['url']
# Download the PGDG repository RPM as a local file
remote_file "#{Chef::Config[:file_cache_path]}/#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}" do
source "#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:url]}#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}"
mode "0644"
remote_file "#{Chef::Config[:file_cache_path]}/#{pgdg_package}" do
source "#{pgdg_repository}#{pgdg_package}"
mode '0644'
end
# Install the PGDG repository RPM from the local file
package "#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}" do
package pgdg_package.to_s do
provider Chef::Provider::Package::Rpm
source "#{Chef::Config[:file_cache_path]}/#{node[:postgresql][:pgdg][:repo_rpm_url][node[:postgresql][:version]][rpm_platform][rpm_platform_version][arch][:package]}"
source "#{Chef::Config[:file_cache_path]}/#{pgdg_package}"
action :install
end