commit 29695f937e2c5ed07cea6a91bb329c806fc3a95d Author: Nico Schottelius Date: Mon May 11 20:42:31 2015 +0200 Initial import from repo Signed-off-by: Nico Schottelius diff --git a/README b/README new file mode 120000 index 0000000..f6bc361 --- /dev/null +++ b/README @@ -0,0 +1 @@ +man.text \ No newline at end of file diff --git a/gencode-remote b/gencode-remote new file mode 100644 index 0000000..30ad3d3 --- /dev/null +++ b/gencode-remote @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 2013-2015 ungleich GmbH (cdist at ungleich.ch) +# +# This file is part of cdist. +# +# cdist 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. +# +# cdist 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 cdist. If not, see . +# + +if [ -f "$__object/parameter/password") ]; then + user="$(cat "$__object/parameter/user")" + password="$(cat "$__object/parameter/password")" + echo "su - postgres -c \"psql -c \\\"ALTER ROLE $user WITH PASSWORD '$password'\\\"\"" +fi diff --git a/man.text b/man.text new file mode 100644 index 0000000..5069379 --- /dev/null +++ b/man.text @@ -0,0 +1,64 @@ +cdist-type__ungleich_postgresql(7) +======================================= +ungleich GmbH + + +NAME +---- +cdist-type__ungleich_postgresql - Setup PostgreSQL with backup + + +DESCRIPTION +----------- +Setup postgresql including some roles for application access + +The development of this type was made possible by Panter AG (www.panter.ch). + +REQUIRED PARAMETERS +------------------- +user:: + Which system user to grant access to the database (creates a role) + + +OPTIONAL PARAMETERS +------------------- +password:: + Setup password for tcp based connections +version:: + Define PostgreSQL version to use instead of default + + +BOOLEAN PARAMETERS +------------------ +no-backup:: + Do not backup database regulary + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__ungleich_postgresql --user app + +# Setup password for tcp based connections (tcp not enabled by this type though) +__ungleich_postgresql --user app --password 'hashedpw' + +# Select different version (must be available in the repository) +__ungleich_postgresql --user app --version 9.2 + +# Do not create backups +__ungleich_postgresql --user app --no-backup + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2013-2015 ungleich GmbH (www.ungleich.ch). +Free use of this software is granted under the terms +of the GNU General Public License version 3 (GPLv3). diff --git a/manifest b/manifest new file mode 100644 index 0000000..0beb6d3 --- /dev/null +++ b/manifest @@ -0,0 +1,96 @@ +#!/bin/sh +# +# 2013-2015 ungleich GmbH (cdist at ungleich.ch) +# +# This file is part of cdist. +# +# cdist 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. +# +# cdist 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 cdist. If not, see . +# + +user="$(cat "$__object/parameter/user")" + +os=$(cat $__global/explorer/os) +osversion=$(cat "$__global/explorer/os_version") + +case "$os" in + debian) + postgres_lib=libpq-dev + + case $osversion in + 6*) + postgres_version=8.4 + ;; + 7*) + postgres_version=9.1 + ;; + 8*) + postgres_version=9.4 + ;; + *) + echo "Unsupported OS Version: $osversion" >&2 + exit 1 + ;; + esac + ;; + *) + echo "Unsupported OS: $os" >&2 + exit 1 + ;; +esac + +# Allow version override +if [ -f "$__object/parameter/version" ]; then + postgres_version=$(cat "$__object/parameter/version") +fi + +postgres_server="postgresql-${postgres_version}" + +################################################################################ +# Configure PostgreSQL +# + +require="__package/$postgres_server" __postgres_role "$user" \ + --state present --login --createdb + +__package "$postgres_server" --state present + +require="__package/$postgres_server" __start_on_boot postgresql + +################################################################################ +# Create backups +# + +if [ ! -f "$__object/parameter/no-backup" ]; then + require="__package/$postgres_server" __directory /var/backups/postgres \ + --owner postgres --group postgres + + require="__package/$postgres_server __directory/var/backups/postgres" __cron \ + pg_dumpall_under_day \ + --user postgres \ + --hour 8,9,10,11,12,14,15,16,17,18 --minute 0 \ + --command 'nice pg_dumpall | gzip > /var/backups/postgres/dumpall-$(date +\%H\%M).sql.gz' + + require="__package/$postgres_server __directory/var/backups/postgres" __cron \ + pg_dumpall_archive \ + --user postgres \ + --hour 2 --minute 0 \ + --command 'nice pg_dumpall | gzip > /var/backups/postgres/dumpall-$(date +\%Y\%m\%d-\%H\%M).sql.gz' + + # Delete local backups after 7 days + require="__package/$postgres_server __directory/var/backups/postgres" __cron \ + pg_dump_cleanup \ + --user postgres \ + --hour 1 --minute 0 \ + --command 'find /var/backups/postgres -type f -mtime +7 -delete' +fi diff --git a/parameter/boolean b/parameter/boolean new file mode 100644 index 0000000..13ba4fb --- /dev/null +++ b/parameter/boolean @@ -0,0 +1 @@ +no-backup diff --git a/parameter/optional b/parameter/optional new file mode 100644 index 0000000..088eda4 --- /dev/null +++ b/parameter/optional @@ -0,0 +1 @@ +version diff --git a/parameter/required b/parameter/required new file mode 100644 index 0000000..4eb8387 --- /dev/null +++ b/parameter/required @@ -0,0 +1 @@ +user diff --git a/singleton b/singleton new file mode 100644 index 0000000..e69de29