Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Boxiang Sun
slapos
Commits
b8fe2e7c
Commit
b8fe2e7c
authored
Sep 19, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added recipe and software release for postgres
parent
e133f381
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
230 additions
and
0 deletions
+230
-0
setup.py
setup.py
+1
-0
slapos/recipe/postgres/__init__.py
slapos/recipe/postgres/__init__.py
+136
-0
software/postgres/instance.cfg.in
software/postgres/instance.cfg.in
+68
-0
software/postgres/software.cfg
software/postgres/software.cfg
+25
-0
No files found.
setup.py
View file @
b8fe2e7c
...
...
@@ -107,6 +107,7 @@ setup(name=name,
'novnc = slapos.recipe.novnc:Recipe'
,
'onetimeupload = slapos.recipe.onetimeupload:Recipe'
,
'pbs = slapos.recipe.pbs:Recipe'
,
'postgres = slapos.recipe.postgres:Recipe'
,
'proactive = slapos.recipe.proactive:Recipe'
,
'publish = slapos.recipe.publish:Recipe'
,
'publishurl = slapos.recipe.publishurl:Recipe'
,
...
...
slapos/recipe/postgres/__init__.py
0 → 100644
View file @
b8fe2e7c
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
os
import
sys
import
subprocess
import
textwrap
from
zc.buildout
import
UserError
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
slapos.recipe.librecipe
import
filehash
class
Recipe
(
GenericBaseRecipe
):
def
_options
(
self
,
options
):
options
[
'password'
]
=
self
.
generatePassword
()
options
[
'url'
]
=
'postgresql://%(user)s:%(password)s/%(host)s:%(port)s/%(dbname)s'
%
dict
(
options
,
host
=
options
[
'ipv6_host'
].
pop
())
def
install
(
self
):
self
.
createCluster
()
self
.
createConfig
()
self
.
createDatabase
()
self
.
createRunScript
()
pgdata
=
self
.
options
[
'pgdata-directory'
]
return
[
os
.
path
.
join
(
pgdata
,
'postgresql.conf'
)
]
def
createCluster
(
self
):
initdb_binary
=
os
.
path
.
join
(
self
.
options
[
'bin'
],
'initdb'
)
pgdata
=
self
.
options
[
'pgdata-directory'
]
if
not
os
.
path
.
exists
(
pgdata
):
try
:
subprocess
.
check_call
([
initdb_binary
,
'-D'
,
pgdata
,
'-A'
,
'ident'
,
'-E'
,
'UTF8'
,
])
except
subprocess
.
CalledProcessError
:
raise
UserError
(
'Could not create cluster directory in %s'
%
pgdata
)
def
createConfig
(
self
):
pgdata
=
self
.
options
[
'pgdata-directory'
]
with
open
(
os
.
path
.
join
(
pgdata
,
'postgresql.conf'
),
'wb'
)
as
cfg
:
cfg
.
write
(
textwrap
.
dedent
(
"""
\
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'
"""
))
with
open
(
os
.
path
.
join
(
pgdata
,
'pg_hba.conf'
),
'wb'
)
as
cfg
:
# see http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html
cfg
.
write
(
textwrap
.
dedent
(
"""
\
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication slapuser4 ident
#host replication slapuser4 127.0.0.1/32 md5
#host replication slapuser4 ::1/128 md5
"""
))
def
createDatabase
(
self
):
pgdata
=
self
.
options
[
'pgdata-directory'
]
postgres_binary
=
os
.
path
.
join
(
self
.
options
[
'bin'
],
'postgres'
)
try
:
p
=
subprocess
.
Popen
([
postgres_binary
,
'--single'
,
'-D'
,
pgdata
,
'postgres'
,
],
stdin
=
subprocess
.
PIPE
)
p
.
communicate
(
'CREATE DATABASE %s
\
n
'
%
self
.
options
[
'dbname'
])
except
subprocess
.
CalledProcessError
:
raise
UserError
(
'Could not create database %s'
%
pgdata
)
def
createRunScript
(
self
):
content
=
textwrap
.
dedent
(
"""
\
#!/bin/sh
%(bin)s/postgres
\
\
-D %(pgdata-directory)s
"""
%
self
.
options
)
name
=
os
.
path
.
join
(
self
.
options
[
'services'
],
'postgres-start'
)
self
.
createExecutable
(
name
,
content
=
content
)
software/postgres/instance.cfg.in
0 → 100644
View file @
b8fe2e7c
[buildout]
parts =
symlinks
publish
postgres-instance
# Define egg directories to be the one from Software Release
# (/opt/slapgrid/...)
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[instance-parameters]
# Fetches parameters defined in SlapOS Master for this instance
recipe = slapos.cookbook:slapconfiguration
computer = $${slap-connection:computer-id}
partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
[directories]
recipe = slapos.cookbook:mkdirectory
bin = $${buildout:directory}/bin
etc = $${buildout:directory}/etc
services = $${directories:etc}/run/
promises = $${directories:etc}/promise/
var = $${buildout:directory}/var
[symlinks]
recipe = cns.recipe.symlink
symlink_target = $${directories:bin}
symlink_base = ${postgresql:location}/bin
[postgres-instance]
# create cluster, configuration files and a database
recipe = slapos.cookbook:postgres
# Options
ipv6_host = $${instance-parameters:ipv6}
user = user
port = 5432
dbname = db
# pgdata_directory is created by initdb, and should not exist beforehand.
pgdata-directory = $${directories:var}/data
services = $${directories:services}
bin = $${directories:bin}
[publish]
recipe = slapos.cookbook:publishurl
url = $${postgres-instance:url}
[slap-connection]
# part to migrate to new - separated words
computer-id = $${slap_connection:computer_id}
partition-id = $${slap_connection:partition_id}
server-url = $${slap_connection:server_url}
software-release-url = $${slap_connection:software_release_url}
key-file = $${slap_connection:key_file}
cert-file = $${slap_connection:cert_file}
software/postgres/software.cfg
0 → 100644
View file @
b8fe2e7c
[buildout]
extends =
../../stack/slapos.cfg
../../component/postgresql/buildout.cfg
parts =
eggs
slapos-cookbook
instance-template
postgresql
[instance-template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/template.cfg
#md5sum =
mode = 0644
[eggs]
recipe = zc.recipe.egg
eggs =
cns.recipe.symlink
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