server_maint 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/lib/cookbooks/postgresql/.gitignore +7 -0
- data/lib/cookbooks/postgresql/.ruby-version +1 -0
- data/lib/cookbooks/postgresql/LICENSE.txt +20 -0
- data/lib/cookbooks/postgresql/README.md +588 -0
- data/lib/cookbooks/postgresql/Rakefile +35 -0
- data/lib/cookbooks/postgresql/attributes/default.rb +365 -0
- data/lib/cookbooks/postgresql/definitions/pg_database.rb +61 -0
- data/lib/cookbooks/postgresql/definitions/pg_database_extensions.rb +67 -0
- data/lib/cookbooks/postgresql/definitions/pg_user.rb +45 -0
- data/lib/cookbooks/postgresql/files/default/pgdg.pref +3 -0
- data/lib/cookbooks/postgresql/metadata.rb +22 -0
- data/lib/cookbooks/postgresql/recipes/client.rb +8 -0
- data/lib/cookbooks/postgresql/recipes/contrib.rb +8 -0
- data/lib/cookbooks/postgresql/recipes/dbg.rb +8 -0
- data/lib/cookbooks/postgresql/recipes/default.rb +50 -0
- data/lib/cookbooks/postgresql/recipes/doc.rb +8 -0
- data/lib/cookbooks/postgresql/recipes/libpq.rb +9 -0
- data/lib/cookbooks/postgresql/recipes/postgis.rb +8 -0
- data/lib/cookbooks/postgresql/recipes/server.rb +118 -0
- data/lib/cookbooks/postgresql/templates/default/environment.erb +11 -0
- data/lib/cookbooks/postgresql/templates/default/pg_ctl.conf.erb +5 -0
- data/lib/cookbooks/postgresql/templates/default/pg_hba.conf.erb +100 -0
- data/lib/cookbooks/postgresql/templates/default/pg_ident.conf.erb +46 -0
- data/lib/cookbooks/postgresql/templates/default/postgresql.conf.custom.erb +10 -0
- data/lib/cookbooks/postgresql/templates/default/postgresql.conf.standard.erb +558 -0
- data/lib/cookbooks/postgresql/templates/default/start.conf.erb +9 -0
- data/lib/cookbooks/postgresql/test/.chef/knife.rb +2 -0
- data/lib/cookbooks/postgresql/test/support/Gemfile +5 -0
- data/lib/server_maint/version.rb +1 -1
- metadata +32 -4
@@ -0,0 +1,67 @@
|
|
1
|
+
define :pg_database_extensions, :action => :create do
|
2
|
+
|
3
|
+
dbname = params[:name]
|
4
|
+
languages = [params[:languages] || []].flatten # Allow single value or array of values
|
5
|
+
extensions = [params[:extensions] || []].flatten
|
6
|
+
postgis = params[:postgis]
|
7
|
+
|
8
|
+
postgresql_version = node["postgresql"]["version"]
|
9
|
+
postgis_version = node["postgis"]["version"]
|
10
|
+
|
11
|
+
case params[:action]
|
12
|
+
when :create
|
13
|
+
|
14
|
+
languages.each do |language|
|
15
|
+
execute "createlang #{language} #{dbname}" do
|
16
|
+
user "postgres"
|
17
|
+
not_if "psql -c 'SELECT lanname FROM pg_catalog.pg_language' #{dbname} | grep '^ #{language}$'", :user => "postgres"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
extensions.each do |extension|
|
22
|
+
execute "psql -c 'CREATE EXTENSION IF NOT EXISTS #{extension}' #{dbname}" do
|
23
|
+
user "postgres"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if postgis
|
28
|
+
include_recipe 'postgresql::postgis'
|
29
|
+
|
30
|
+
execute "psql -d #{dbname} -f /usr/share/postgresql/#{postgresql_version}/contrib/postgis-#{postgis_version}/postgis.sql" do
|
31
|
+
user "postgres"
|
32
|
+
not_if "psql -c \"SELECT proname FROM pg_catalog.pg_proc WHERE proname = 'st_area'\" #{dbname} | grep 'st_area$'", :user => "postgres"
|
33
|
+
end
|
34
|
+
|
35
|
+
execute "psql -d #{dbname} -f /usr/share/postgresql/#{postgresql_version}/contrib/postgis-#{postgis_version}/spatial_ref_sys.sql" do
|
36
|
+
user "postgres"
|
37
|
+
only_if "psql -c 'SELECT count(1) FROM spatial_ref_sys' #{dbname} | grep '0$'", :user => "postgres"
|
38
|
+
end
|
39
|
+
|
40
|
+
[:geometry_columns, :geography_columns, :spatial_ref_sys].each do |table|
|
41
|
+
execute "psql -c 'GRANT ALL ON #{table} TO PUBLIC' #{dbname}" do
|
42
|
+
user "postgres"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
when :drop
|
48
|
+
|
49
|
+
languages.each do |language|
|
50
|
+
execute "droplang #{language} #{dbname}" do
|
51
|
+
user "postgres"
|
52
|
+
only_if "psql -c 'SELECT lanname FROM pg_catalog.pg_language' #{dbname} | grep '^ #{language}$'", :user => "postgres"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
extensions.each do |extension|
|
57
|
+
execute "psql -c 'DROP EXTENSION IF EXISTS #{extension}' #{dbname}" do
|
58
|
+
user "postgres"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if postgis
|
63
|
+
Chef::Log.warn("Postgis support dropping isn't supported")
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
define :pg_user, :action => :create do
|
2
|
+
case params[:action]
|
3
|
+
when :create
|
4
|
+
privileges = {
|
5
|
+
:superuser => false,
|
6
|
+
:createdb => false,
|
7
|
+
:login => true
|
8
|
+
}
|
9
|
+
privileges.merge! params[:privileges] if params[:privileges]
|
10
|
+
|
11
|
+
sql = [params[:name]]
|
12
|
+
|
13
|
+
sql.push privileges.to_a.map! { |p,b| (b ? '' : 'NO') + p.to_s.upcase }.join ' '
|
14
|
+
|
15
|
+
if params[:encrypted_password]
|
16
|
+
sql.push "ENCRYPTED PASSWORD '#{params[:encrypted_password]}'"
|
17
|
+
elsif params[:password]
|
18
|
+
sql.push "PASSWORD '#{params[:password]}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
sql = sql.join ' '
|
22
|
+
|
23
|
+
exists = ["psql -c \"SELECT usename FROM pg_user WHERE usename='#{params[:name]}'\""]
|
24
|
+
exists.push "| grep #{params[:name]}"
|
25
|
+
exists = exists.join ' '
|
26
|
+
|
27
|
+
execute "altering pg user #{params[:name]}" do
|
28
|
+
user "postgres"
|
29
|
+
command "psql -c \"ALTER ROLE #{sql}\""
|
30
|
+
only_if exists, :user => "postgres"
|
31
|
+
end
|
32
|
+
|
33
|
+
execute "creating pg user #{params[:name]}" do
|
34
|
+
user "postgres"
|
35
|
+
command "psql -c \"CREATE ROLE #{sql}\""
|
36
|
+
not_if exists, :user => "postgres"
|
37
|
+
end
|
38
|
+
|
39
|
+
when :drop
|
40
|
+
execute "dropping pg user #{params[:name]}" do
|
41
|
+
user "postgres"
|
42
|
+
command "psql -c \"DROP ROLE IF EXISTS #{params[:name]}\""
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name "postgresql"
|
2
|
+
maintainer "Phil Cohen"
|
3
|
+
maintainer_email "github@phlippers.net"
|
4
|
+
license "MIT"
|
5
|
+
description "Installs PostgreSQL, The world's most advanced open source database."
|
6
|
+
long_description IO.read(File.join(File.dirname(__FILE__), "README.md"))
|
7
|
+
version "0.9.0"
|
8
|
+
|
9
|
+
recipe "postgresql", "Set up the apt repository and install dependent packages"
|
10
|
+
recipe "postgresql::client", "Front-end programs for PostgreSQL 9.x"
|
11
|
+
recipe "postgresql::server", "Object-relational SQL database, version 9.x server"
|
12
|
+
recipe "postgresql::contrib", "Additional facilities for PostgreSQL"
|
13
|
+
recipe "postgresql::dbg", "Debug symbols for the server daemon"
|
14
|
+
recipe "postgresql::doc", "Documentation for the PostgreSQL database management system"
|
15
|
+
recipe "postgresql::libpq", "PostgreSQL C client library and header files for libpq5 (PostgreSQL library)"
|
16
|
+
recipe "postgresql::postgis", "Geographic objects support for PostgreSQL 9.x"
|
17
|
+
|
18
|
+
%w[ubuntu debian].each do |os|
|
19
|
+
supports os
|
20
|
+
end
|
21
|
+
|
22
|
+
depends "apt"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: postgresql
|
3
|
+
# Recipe:: default
|
4
|
+
#
|
5
|
+
|
6
|
+
case node["platform"]
|
7
|
+
when "ubuntu"
|
8
|
+
|
9
|
+
apt_repository "pitti-postgresql" do
|
10
|
+
uri "http://ppa.launchpad.net/pitti/postgresql/ubuntu"
|
11
|
+
distribution node["lsb"]["codename"]
|
12
|
+
components ["main"]
|
13
|
+
keyserver "keyserver.ubuntu.com"
|
14
|
+
key "8683D8A2"
|
15
|
+
action :add
|
16
|
+
end
|
17
|
+
|
18
|
+
# install common files
|
19
|
+
package "postgresql-common"
|
20
|
+
|
21
|
+
when "debian"
|
22
|
+
|
23
|
+
# backports for initial support
|
24
|
+
apt_repository "debian-backports" do
|
25
|
+
uri "http://backports.debian.org/debian-backports"
|
26
|
+
distribution "#{node["lsb"]["codename"]}-backports"
|
27
|
+
components ["main"]
|
28
|
+
action :add
|
29
|
+
end
|
30
|
+
|
31
|
+
cookbook_file "/etc/apt/preferences.d/pgdg.pref" do
|
32
|
+
source "pgdg.pref"
|
33
|
+
end
|
34
|
+
|
35
|
+
# backports support for debian
|
36
|
+
%w[libpq5 postgresql-common].each do |pkg|
|
37
|
+
package pkg do
|
38
|
+
options "-t #{node["lsb"]["codename"]}-backports"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# use `apt.postgresql.org` for primary package installation support
|
43
|
+
apt_repository "apt.postgresql.org" do
|
44
|
+
uri "http://apt.postgresql.org/pub/repos/apt"
|
45
|
+
distribution "#{node["lsb"]["codename"]}-pgdg"
|
46
|
+
components ["main"]
|
47
|
+
key "http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc"
|
48
|
+
action :add
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: postgresql
|
3
|
+
# Recipe:: server
|
4
|
+
#
|
5
|
+
|
6
|
+
include_recipe "postgresql"
|
7
|
+
|
8
|
+
pg_version = node["postgresql"]["version"]
|
9
|
+
|
10
|
+
# install the package
|
11
|
+
package "postgresql-#{pg_version}"
|
12
|
+
|
13
|
+
|
14
|
+
# ensure data directory exists
|
15
|
+
directory node["postgresql"]["data_directory"] do
|
16
|
+
owner "postgres"
|
17
|
+
group "postgres"
|
18
|
+
mode "0700"
|
19
|
+
not_if "test -f #{node["postgresql"]["data_directory"]}/PG_VERSION"
|
20
|
+
end
|
21
|
+
|
22
|
+
# initialize the data directory if necessary
|
23
|
+
bash "postgresql initdb" do
|
24
|
+
user "postgres"
|
25
|
+
code <<-EOC
|
26
|
+
/usr/lib/postgresql/#{pg_version}/bin/initdb \
|
27
|
+
#{node["postgresql"]["initdb_options"]} \
|
28
|
+
-U postgres \
|
29
|
+
-D #{node["postgresql"]["data_directory"]}
|
30
|
+
EOC
|
31
|
+
creates "#{node["postgresql"]["data_directory"]}/PG_VERSION"
|
32
|
+
end
|
33
|
+
|
34
|
+
# environment
|
35
|
+
template "/etc/postgresql/#{pg_version}/main/environment" do
|
36
|
+
source "environment.erb"
|
37
|
+
owner "postgres"
|
38
|
+
group "postgres"
|
39
|
+
mode "0644"
|
40
|
+
notifies :restart, "service[postgresql]"
|
41
|
+
end
|
42
|
+
|
43
|
+
# pg_ctl
|
44
|
+
template "/etc/postgresql/#{pg_version}/main/pg_ctl.conf" do
|
45
|
+
source "pg_ctl.conf.erb"
|
46
|
+
owner "postgres"
|
47
|
+
group "postgres"
|
48
|
+
mode "0644"
|
49
|
+
notifies :restart, "service[postgresql]"
|
50
|
+
end
|
51
|
+
|
52
|
+
# pg_hba
|
53
|
+
template node["postgresql"]["hba_file"] do
|
54
|
+
source "pg_hba.conf.erb"
|
55
|
+
owner "postgres"
|
56
|
+
group "postgres"
|
57
|
+
mode "0640"
|
58
|
+
notifies :restart, "service[postgresql]"
|
59
|
+
end
|
60
|
+
|
61
|
+
# pg_ident
|
62
|
+
template node["postgresql"]["ident_file"] do
|
63
|
+
source "pg_ident.conf.erb"
|
64
|
+
owner "postgres"
|
65
|
+
group "postgres"
|
66
|
+
mode "0640"
|
67
|
+
notifies :restart, "service[postgresql]"
|
68
|
+
end
|
69
|
+
|
70
|
+
# postgresql
|
71
|
+
pg_template_source = node["postgresql"]["conf"].any? ? "custom" : "standard"
|
72
|
+
template "/etc/postgresql/#{pg_version}/main/postgresql.conf" do
|
73
|
+
source "postgresql.conf.#{pg_template_source}.erb"
|
74
|
+
owner "postgres"
|
75
|
+
group "postgres"
|
76
|
+
mode "0644"
|
77
|
+
variables(:configuration => node["postgresql"]["conf"])
|
78
|
+
notifies :restart, "service[postgresql]"
|
79
|
+
end
|
80
|
+
|
81
|
+
# start
|
82
|
+
template "/etc/postgresql/#{pg_version}/main/start.conf" do
|
83
|
+
source "start.conf.erb"
|
84
|
+
owner "postgres"
|
85
|
+
group "postgres"
|
86
|
+
mode "0644"
|
87
|
+
notifies :restart, "service[postgresql]", :immediately
|
88
|
+
end
|
89
|
+
|
90
|
+
# setup users
|
91
|
+
node["postgresql"]["users"].each do |user|
|
92
|
+
pg_user user["username"] do
|
93
|
+
privileges :superuser => user["superuser"], :createdb => user["createdb"], :login => user["login"]
|
94
|
+
password user["password"]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# setup databases
|
99
|
+
node["postgresql"]["databases"].each do |database|
|
100
|
+
pg_database database["name"] do
|
101
|
+
owner database["owner"]
|
102
|
+
encoding database["encoding"]
|
103
|
+
template database["template"]
|
104
|
+
locale database["locale"]
|
105
|
+
end
|
106
|
+
|
107
|
+
pg_database_extensions database["name"] do
|
108
|
+
extensions database["extensions"]
|
109
|
+
languages database["languages"]
|
110
|
+
postgis database["postgis"]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# define the service
|
115
|
+
service "postgresql" do
|
116
|
+
supports :restart => true
|
117
|
+
action [:enable, :start]
|
118
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# environment variables for postmaster process
|
2
|
+
# This file has the same syntax as postgresql.conf:
|
3
|
+
# VARIABLE = simple_value
|
4
|
+
# VARIABLE2 = 'any value!'
|
5
|
+
# I. e. you need to enclose any value which does not only consist of letters,
|
6
|
+
# numbers, and '-', '_', '.' in single quotes. Shell commands are not
|
7
|
+
# evaluated.
|
8
|
+
|
9
|
+
<% node["postgresql"]["environment_variables"].each_pair do |k, v| %>
|
10
|
+
<%= "#{k} = #{v}" %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# PostgreSQL Client Authentication Configuration File
|
2
|
+
# ===================================================
|
3
|
+
#
|
4
|
+
# Refer to the "Client Authentication" section in the PostgreSQL
|
5
|
+
# documentation for a complete description of this file. A short
|
6
|
+
# synopsis follows.
|
7
|
+
#
|
8
|
+
# This file controls: which hosts are allowed to connect, how clients
|
9
|
+
# are authenticated, which PostgreSQL user names they can use, which
|
10
|
+
# databases they can access. Records take one of these forms:
|
11
|
+
#
|
12
|
+
# local DATABASE USER METHOD [OPTIONS]
|
13
|
+
# host DATABASE USER ADDRESS METHOD [OPTIONS]
|
14
|
+
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
|
15
|
+
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
|
16
|
+
#
|
17
|
+
# (The uppercase items must be replaced by actual values.)
|
18
|
+
#
|
19
|
+
# The first field is the connection type: "local" is a Unix-domain
|
20
|
+
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
|
21
|
+
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
|
22
|
+
# plain TCP/IP socket.
|
23
|
+
#
|
24
|
+
# DATABASE can be "all", "sameuser", "samerole", "replication", a
|
25
|
+
# database name, or a comma-separated list thereof. The "all"
|
26
|
+
# keyword does not match "replication". Access to replication
|
27
|
+
# must be enabled in a separate record (see example below).
|
28
|
+
#
|
29
|
+
# USER can be "all", a user name, a group name prefixed with "+", or a
|
30
|
+
# comma-separated list thereof. In both the DATABASE and USER fields
|
31
|
+
# you can also write a file name prefixed with "@" to include names
|
32
|
+
# from a separate file.
|
33
|
+
#
|
34
|
+
# ADDRESS specifies the set of hosts the record matches. It can be a
|
35
|
+
# host name, or it is made up of an IP address and a CIDR mask that is
|
36
|
+
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
|
37
|
+
# specifies the number of significant bits in the mask. A host name
|
38
|
+
# that starts with a dot (.) matches a suffix of the actual host name.
|
39
|
+
# Alternatively, you can write an IP address and netmask in separate
|
40
|
+
# columns to specify the set of hosts. Instead of a CIDR-address, you
|
41
|
+
# can write "samehost" to match any of the server's own IP addresses,
|
42
|
+
# or "samenet" to match any address in any subnet that the server is
|
43
|
+
# directly connected to.
|
44
|
+
#
|
45
|
+
# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
|
46
|
+
# "krb5", "ident", "peer", "pam", "ldap", "radius" or "cert". Note that
|
47
|
+
# "password" sends passwords in clear text; "md5" is preferred since
|
48
|
+
# it sends encrypted passwords.
|
49
|
+
#
|
50
|
+
# OPTIONS are a set of options for the authentication in the format
|
51
|
+
# NAME=VALUE. The available options depend on the different
|
52
|
+
# authentication methods -- refer to the "Client Authentication"
|
53
|
+
# section in the documentation for a list of which options are
|
54
|
+
# available for which authentication methods.
|
55
|
+
#
|
56
|
+
# Database and user names containing spaces, commas, quotes and other
|
57
|
+
# special characters must be quoted. Quoting one of the keywords
|
58
|
+
# "all", "sameuser", "samerole" or "replication" makes the name lose
|
59
|
+
# its special character, and just match a database or username with
|
60
|
+
# that name.
|
61
|
+
#
|
62
|
+
# This file is read on server startup and when the postmaster receives
|
63
|
+
# a SIGHUP signal. If you edit the file on a running system, you have
|
64
|
+
# to SIGHUP the postmaster for the changes to take effect. You can
|
65
|
+
# use "pg_ctl reload" to do that.
|
66
|
+
|
67
|
+
# Put your actual configuration here
|
68
|
+
# ----------------------------------
|
69
|
+
#
|
70
|
+
# If you want to allow non-local connections, you need to add more
|
71
|
+
# "host" records. In that case you will also need to make PostgreSQL
|
72
|
+
# listen on a non-local interface via the listen_addresses
|
73
|
+
# configuration parameter, or via the -i or -h command line switches.
|
74
|
+
|
75
|
+
<% node["postgresql"]["pg_hba"].each do |hba| %>
|
76
|
+
<%= hba['type'] %> <%= hba['db'] %> <%= hba['user'] %> <%= hba['addr'] %> <%= hba['method'] %>
|
77
|
+
<% end %>
|
78
|
+
|
79
|
+
# DO NOT DISABLE!
|
80
|
+
# If you change this first entry you will need to make sure that the
|
81
|
+
# database superuser can access the database using some other method.
|
82
|
+
# Noninteractive access to all databases is required during automatic
|
83
|
+
# maintenance (custom daily cronjobs, replication, and similar tasks).
|
84
|
+
#
|
85
|
+
# TYPE DATABASE USER ADDRESS METHOD
|
86
|
+
<% if node[:postgresql][:pg_hba_defaults] %>
|
87
|
+
# Database administrative login by Unix domain socket
|
88
|
+
local all postgres peer
|
89
|
+
# "local" is for Unix domain socket connections only
|
90
|
+
local all all peer
|
91
|
+
# IPv4 local connections:
|
92
|
+
host all all 127.0.0.1/32 md5
|
93
|
+
# IPv6 local connections:
|
94
|
+
host all all ::1/128 md5
|
95
|
+
# Allow replication connections from localhost, by a user with the
|
96
|
+
# replication privilege.
|
97
|
+
#local replication postgres peer
|
98
|
+
#host replication postgres 127.0.0.1/32 md5
|
99
|
+
#host replication postgres ::1/128 md5
|
100
|
+
<% end %>
|