Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos-caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Guillaume Hervier
slapos-caddy
Commits
9fc75a3e
Commit
9fc75a3e
authored
Jun 05, 2014
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postgres recipe: always update configuration files
parent
8ac212c0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
45 deletions
+64
-45
slapos/recipe/postgres/__init__.py
slapos/recipe/postgres/__init__.py
+33
-40
software/postgres/instance.cfg.in
software/postgres/instance.cfg.in
+28
-4
software/postgres/software.cfg
software/postgres/software.cfg
+3
-1
No files found.
slapos/recipe/postgres/__init__.py
View file @
9fc75a3e
...
@@ -76,14 +76,16 @@ class Recipe(GenericBaseRecipe):
...
@@ -76,14 +76,16 @@ class Recipe(GenericBaseRecipe):
def
install
(
self
):
def
install
(
self
):
pgdata
=
self
.
options
[
'pgdata-directory'
]
pgdata
=
self
.
options
[
'pgdata-directory'
]
# if the pgdata already exists,
skip all steps, we don't need to do anything
.
# if the pgdata already exists,
only update the configuration files
.
if
not
os
.
path
.
exists
(
pgdata
):
if
not
os
.
path
.
exists
(
pgdata
):
self
.
createCluster
()
self
.
createCluster
()
self
.
cre
ateConfig
()
self
.
upd
ateConfig
()
self
.
createDatabase
()
self
.
createDatabase
()
self
.
updateSuperuser
()
self
.
updateSuperuser
()
self
.
createRunScript
()
self
.
createRunScript
()
else
:
self
.
updateConfig
()
# install() methods usually return the pathnames of managed files.
# install() methods usually return the pathnames of managed files.
# If they are missing, they will be rebuilt.
# If they are missing, they will be rebuilt.
...
@@ -121,53 +123,44 @@ class Recipe(GenericBaseRecipe):
...
@@ -121,53 +123,44 @@ class Recipe(GenericBaseRecipe):
raise
UserError
(
'Could not create cluster directory in %s'
%
pgdata
)
raise
UserError
(
'Could not create cluster directory in %s'
%
pgdata
)
def
createConfig
(
self
):
def
updateConfig
(
self
):
ret
=
[]
pgdata
=
self
.
options
[
'pgdata-directory'
]
pgdata
=
self
.
options
[
'pgdata-directory'
]
ipv4
=
self
.
options
[
'ipv4'
]
ipv4
=
self
.
options
[
'ipv4'
]
ipv6
=
self
.
options
[
'ipv6'
]
ipv6
=
self
.
options
[
'ipv6'
]
with
open
(
os
.
path
.
join
(
pgdata
,
'postgresql.conf'
),
'wb'
)
as
cfg
:
postgresql_conf_path
=
os
.
path
.
join
(
pgdata
,
'postgresql.conf'
)
cfg
.
write
(
textwrap
.
dedent
(
"""
\
with
open
(
postgresql_conf_path
,
'wb'
)
as
cfg
:
listen_addresses = '%s'
ret
.
append
(
postgresql_conf_path
)
logging_collector = on
template
=
self
.
options
[
'template-postgresql-conf'
].
lstrip
()
log_rotation_size = 50MB
cfg
.
write
(
template
.
format
(
listen_addresses
=
','
.
join
(
ipv4
.
union
(
ipv6
)),
max_connections = 100
unix_socket_directory
=
pgdata
))
datestyle = 'iso, mdy'
cfg
.
write
(
'
\
n
'
)
lc_messages = 'en_US.UTF-8'
pghba_conf_path
=
os
.
path
.
join
(
pgdata
,
'pg_hba.conf'
)
lc_monetary = 'en_US.UTF-8'
with
open
(
pghba_conf_path
,
'wb'
)
as
cfg
:
lc_numeric = 'en_US.UTF-8'
ret
.
append
(
pghba_conf_path
)
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
unix_socket_directory = '%s'
unix_socket_permissions = 0700
"""
%
(
','
.
join
(
ipv4
.
union
(
ipv6
)),
pgdata
,
)))
with
open
(
os
.
path
.
join
(
pgdata
,
'pg_hba.conf'
),
'wb'
)
as
cfg
:
# see http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html
# see http://www.postgresql.org/docs/9.2/static/auth-pg-hba-conf.html
cfg_lines
=
[
template_hba_ipv4
=
self
.
options
.
get
(
'template-hba-ipv4'
).
strip
()
'# TYPE DATABASE USER ADDRESS METHOD'
,
ipv4_auth
=
''
''
,
if
template_hba_ipv4
:
'# "local" is for Unix domain socket connections only (check unix_socket_permissions!)'
,
'local all all trust'
,
'host all all 127.0.0.1/32 md5'
,
'host all all ::1/128 md5'
,
]
ipv4_netmask_bits
=
self
.
options
.
get
(
'ipv4-netmask-bits'
,
'32'
)
for
ip
in
ipv4
:
for
ip
in
ipv4
:
cfg_lines
.
append
(
'host all all %s/%s md5'
%
(
ip
,
ipv4_netmask_bits
)
)
ipv4_auth
+=
template_hba_ipv4
.
format
(
ip
=
ip
)
ipv6_netmask_bits
=
self
.
options
.
get
(
'ipv6-netmask-bits'
,
'128'
)
template_hba_ipv6
=
self
.
options
.
get
(
'template-hba-ipv6'
).
strip
()
ipv6_auth
=
''
if
template_hba_ipv6
:
for
ip
in
ipv6
:
for
ip
in
ipv6
:
cfg_lines
.
append
(
'host all all %s/%s md5'
%
(
ip
,
ipv6_netmask_bits
))
ipv6_auth
+=
template_hba_ipv6
.
format
(
ip
=
ip
)
template
=
self
.
options
[
'template-pg-hba-conf'
].
lstrip
()
cfg
.
write
(
template
.
format
(
ipv4_auth
=
ipv4_auth
,
ipv6_auth
=
ipv6_auth
))
cfg
.
write
(
'
\
n
'
)
cfg
.
write
(
'
\
n
'
.
join
(
cfg_lines
))
return
ret
def
createDatabase
(
self
):
def
createDatabase
(
self
):
...
...
software/postgres/instance.cfg.in
View file @
9fc75a3e
...
@@ -31,11 +31,7 @@ recipe = slapos.cookbook:postgres
...
@@ -31,11 +31,7 @@ recipe = slapos.cookbook:postgres
# Options
# Options
ipv6 = $${instance-parameters:ipv6}
ipv6 = $${instance-parameters:ipv6}
# listen to connections from anywhere
ipv6-netmask-bits = 0
ipv4 = $${instance-parameters:ipv4}
ipv4 = $${instance-parameters:ipv4}
# listen to connections from anywhere
ipv4-netmask-bits = 0
ipv6-random = $${instance-parameters:ipv6-random}
ipv6-random = $${instance-parameters:ipv6-random}
superuser = postgres
superuser = postgres
password = $${gen-passwd:passwd}
password = $${gen-passwd:passwd}
...
@@ -45,6 +41,34 @@ dbname = db
...
@@ -45,6 +41,34 @@ dbname = db
pgdata-directory = $${directories:var}/data
pgdata-directory = $${directories:var}/data
bin = ${postgresql:location}/bin
bin = ${postgresql:location}/bin
services = $${directories:services}
services = $${directories:services}
template-postgresql-conf =
# This configuration file is generated by a SlapOS instance profile. Manual edits will be overwritten.
listen_addresses = '{listen_addresses}'
logging_collector = on
log_rotation_size = 50MB
max_connections = 100
datestyle = 'iso, mdy'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
unix_socket_directory = '{unix_socket_directory}'
unix_socket_permissions = 0700
template-pg-hba-conf =
# This configuration file is generated by a SlapOS instance profile. Manual edits will be overwritten.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only (check unix_socket_permissions!)
local all all trust
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
{ipv4_auth}
{ipv6_auth}
template-hba-ipv4 =
host all all {ip}/32 md5
template-hba-ipv6 =
host all all {ip}/128 md5
#----------------
#----------------
...
...
software/postgres/software.cfg
View file @
9fc75a3e
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
extends =
extends =
../../stack/slapos.cfg
../../stack/slapos.cfg
../../component/git/buildout.cfg
../../component/postgresql/buildout.cfg
../../component/postgresql/buildout.cfg
parts =
parts =
...
@@ -17,9 +18,10 @@ parts =
...
@@ -17,9 +18,10 @@ parts =
recipe = slapos.recipe.template
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
url = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/instance.cfg
output = ${buildout:directory}/instance.cfg
md5sum =
d8b833a2054b82b6031a9420008b58fd
md5sum =
e78188b903d61de2d2e1e36d1d4bbec8
mode = 0644
mode = 0644
[networkcache]
[networkcache]
# signature certificates of the following uploaders.
# signature certificates of the following uploaders.
# Romain Courteaud
# Romain Courteaud
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment