Skip to content

Syncing with upstream #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
be07072
use upstream repo for python if configured
noelmcloughlin Mar 31, 2018
e6be41a
Merge branch 'master' into python
noelmcloughlin May 17, 2018
06e5944
Allow `port` to be configurable
myii Jun 8, 2018
6840bf3
Merge pull request #204 from noelmcloughlin/python
noelmcloughlin Jun 9, 2018
0d9a5ba
Append `Managed by SaltStack` comment to `port` setting
myii Jun 10, 2018
8fce906
tidyup bad jinja2 syntax
Jun 11, 2018
d9c071a
Merge pull request #219 from noelmcloughlin/better_jinja_syntax
noelmcloughlin Jun 12, 2018
e1a19ed
Use top-level `postgres.port` and existing states to set `port`
myii Jun 12, 2018
6568325
Use separate state for restarting service re: `postgresql.conf`
myii Jun 12, 2018
311cb3d
Enable replication connections by default in `pg_hba.conf`
myii Jun 8, 2018
9fdce93
Set default version to `10`
myii Jun 8, 2018
ee532da
Client should not install dev libs by default
t0fik Jun 14, 2018
e474db9
Use upstream instructions for Apt `pkg_repo` (remove unnecessary `ver…
myii Jun 16, 2018
79ab1a2
Avoid duplicate Jinja conditional block by moving service restart
myii Jun 16, 2018
e3ffa44
Handle postgres dev package dependencies
Jun 11, 2018
81919a9
Merge pull request #224 from jdsieci/remove_install_dev_by_default
noelmcloughlin Jun 16, 2018
04a09dc
add fromrepo support for client binaries
noelmcloughlin Jun 16, 2018
70ee621
fix typo in package name
noelmcloughlin Jun 16, 2018
4a80599
Merge pull request #227 from noelmcloughlin/fixtypo
aboe76 Jun 17, 2018
0c6f9a4
Merge pull request #225 from myii/patch-1
aboe76 Jun 17, 2018
844ae97
Merge pull request #218 from myii/PR_port
aboe76 Jun 17, 2018
761b1ca
Merge pull request #226 from noelmcloughlin/fromrepo2
aboe76 Jun 17, 2018
bbe6fb3
Fix 'fromrepo' bug in fedora macro
noelmcloughlin Jun 17, 2018
85fb4bf
Merge pull request #229 from noelmcloughlin/fixbug
aboe76 Jun 17, 2018
501b0b6
Merge pull request #221 from noelmcloughlin/devpkg
aboe76 Jun 18, 2018
764863f
Split conf/data directories, support
noelmcloughlin Jun 18, 2018
bdbc784
limits file has jinja context; fix #213
Jun 11, 2018
aa91079
Merge pull request #222 from myii/PR_psql10_acls
aboe76 Jun 19, 2018
a827825
Merge pull request #220 from noelmcloughlin/macos_fix
aboe76 Jun 19, 2018
9865664
Merge pull request #228 from noelmcloughlin/confdata1
aboe76 Jun 20, 2018
c3a32eb
Fix `conf_dir` => `data_dir` required for preparing cluster
myii Jun 21, 2018
67d6b8a
Ensure service starts after cluster created
myii Jun 21, 2018
34aae25
Allow configuration of cluster `name`, `locale` & `encoding`
myii Jun 21, 2018
9ce9891
Remove trailing slash so `pkgrepo.absent` works for Apt
myii Jun 21, 2018
944a077
Fix `pillar.get` for `MacOS` user/group early lookup
myii Jun 21, 2018
007d639
Merge pull request #231 from myii/patch-1
noelmcloughlin Jun 21, 2018
f24b962
Move concatenation of cluster preparation command to `map.jinja`
myii Jun 24, 2018
62675f2
Don't set modes with every run
SuperTux88 Jun 24, 2018
be80f74
Merge pull request #233 from SuperTux88/dont-change-modes
aboe76 Jun 25, 2018
332fe7b
Merge pull request #232 from myii/PR_cluster
aboe76 Jun 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pillar.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Port to use for the cluster -- can be used to provide a non-standard port
# NOTE: If already set in the minion config, that value takes priority
postgres.port: '5432'

postgres:
# UPSTREAM REPO
# Set True to configure upstream postgresql.org repository for YUM/APT/ZYPP
use_upstream_repo: False
# Version to install from upstream repository (if upstream_repo: True)
version: '9.6'
version: '10'
# If automatic package installation fails, use `fromrepo` to specify the
# upstream repo to install packages from [#133, #185] (if upstream_repo: True)
fromrepo: 'jessie-pgdg'
Expand All @@ -22,19 +26,26 @@ postgres:
- postgresql-contrib
- postgresql-plpython

# CLUSTER
# The default `encoding` is derived from the `locale` so not recommended
# to provide a value for it unless necessary
cluster:
locale: en_GB.UTF-8
# encoding: UTF8

#'Alternatives system' priority incremental. 0 disables feature.
linux:
altpriority: 30

# macos limits
limits:
soft: 64000
hard: 64000
hard: 128000

# POSTGRES
# Append the lines under this item to your postgresql.conf file.
# Pay attention to indent exactly with 4 spaces for all lines.
postgresconf: |
postgresconf: |-
listen_addresses = '*' # listen on all interfaces

# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
Expand Down
9 changes: 6 additions & 3 deletions postgres/client/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres with context -%}

{%- set pkgs = [] %}
{%- for pkg in (postgres.pkg_client, postgres.pkg_libpq_dev) %}
{%- for pkg in (postgres.pkg_client,) %}
{%- if pkg %}
{%- do pkgs.append(pkg) %}
{%- endif %}
Expand All @@ -16,11 +16,14 @@ include:
postgresql-client-libs:
pkg.installed:
- pkgs: {{ pkgs }}
{%- if postgres.use_upstream_repo == true %}
{%- if postgres.use_upstream_repo == true %}
- refresh: True
- require:
- pkgrepo: postgresql-repo
{%- endif %}
{%- endif %}
{%- if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{%- endif %}

# Alternatives system. Make client binaries available in $PATH
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
Expand Down
16 changes: 7 additions & 9 deletions postgres/codenamemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@

{% macro debian_codename(name, version, codename=none) %}

{# use upstream version if configured #}
{% if repo.use_upstream_repo == true %}
{% set version = repo.version %}
{% set fromrepo = repo.fromrepo|default(name ~ '-pgdg', true) %}
{% else %}
{% set fromrepo = name %}
{% endif %}
{% set cluster_name = repo.cluster_name %}
{% set conf_dir = '/etc/postgresql/{0}/{1}'.format(version, cluster_name) %}
{% set data_dir = '/var/lib/postgresql/{0}/{1}'.format(version, cluster_name) %}

{{ codename|default(name, true) }}:
# PostgreSQL packages are mostly downloaded from `main` repo component
conf_dir: {{ conf_dir }}
data_dir: {{ data_dir }}
fromrepo: {{ fromrepo }}
pkg_repo:
name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main {{ version }}'
name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main'
pkg: postgresql-{{ version }}
pkg_client: postgresql-client-{{ version }}
conf_dir: /etc/postgresql/{{ version }}/main
prepare_cluster:
command: pg_createcluster {{ version }} main
test: test -f /var/lib/postgresql/{{ version }}/main/PG_VERSION && test -f /etc/postgresql/{{ version }}/main/postgresql.conf
pgcommand: pg_createcluster {{ version }} {{ cluster_name }} -d
user: root

{% endmacro %}
Expand All @@ -38,15 +40,11 @@

{# use upstream version if configured #}
{% if repo.use_upstream_repo == true %}
{% set fromrepo = repo.fromrepo|default(name ~ '-pgdg', true) %}
{% set version = repo.version %}
{% else %}
{% set fromrepo = name %}
{% endif %}

{{ codename|default(name, true) }}:
# PostgreSQL packages are mostly downloaded from `main` repo component
fromrepo: {{ name }}
pkg_repo:
baseurl: 'https://download.postgresql.org/pub/repos/yum/{{ version }}/fedora/fedora-$releasever-$basearch'

Expand Down
18 changes: 15 additions & 3 deletions postgres/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

postgres:
use_upstream_repo: True
version: '9.5'
version: '10'
pkg: postgresql
pkgs_extra: []
pkg_client: postgresql-client
pkg_dev: postgresql-devel
pkg_dev_deps: []
pkg_libpq_dev: libpq-dev
pkg_libs: postgresql-libs
pkg_python: python-psycopg2
Expand All @@ -15,12 +16,18 @@ postgres:
group: postgres

prepare_cluster:
command: initdb --pgdata=/var/lib/pgsql/data
test: test -f /var/lib/pgsql/data/PG_VERSION
pgcommand: initdb -D
pgtestfile: PG_VERSION
user: postgres
env: []

cluster:
name: main # Debian-based only
locale: '' # Defaults to `C`
encoding: '' # Defaults to `SQL_ASCII` if `locale` not provided

conf_dir: /var/lib/pgsql/data
data_dir: /var/lib/pgsql/data
conf_dir_mode: '0700'
postgresconf: ""

Expand All @@ -47,6 +54,11 @@ postgres:
- ['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', 'all', 'peer']
- ['host', 'replication', 'all', '127.0.0.1/32', 'md5']
- ['host', 'replication', 'all', '::1/128', 'md5']

pg_ident.conf: salt://postgres/templates/pg_ident.conf.j2
identity_map: []
Expand Down
23 changes: 8 additions & 15 deletions postgres/dev.sls
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{% from tpldir + "/map.jinja" import postgres with context %}

{% if grains.os not in ('Windows', 'MacOS',) %}
{%- set pkgs = [postgres.pkg_dev, postgres.pkg_libpq_dev] + postgres.pkg_dev_deps %}

{% if postgres.pkg_dev %}
install-postgres-dev-package:
{% if pkgs %}
install-postgres-dev-packages:
pkg.installed:
- name: {{ postgres.pkg_dev }}
- pkgs: {{ pkgs }}
{% if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{% endif %}
{% endif %}

{% if postgres.pkg_libpq_dev %}
install-postgres-libpq-dev:
pkg.installed:
- name: {{ postgres.pkg_libpq_dev }}
{% if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{% endif %}
{% endif %}

# Alternatives system. Make devclient binaries available in $PATH
# Alternatives system. Make devclient binaries available in $PATH
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- for bin in postgres.dev_bins %}
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}
Expand All @@ -45,9 +37,10 @@ postgres_maxfiles_limits_conf:
file.managed:
- name: /Library/LaunchDaemons/limit.maxfiles.plist
- source: salt://{{ tpldir }}/templates/limit.maxfiles.plist
- template: jinja
- context:
soft_limit: {{ postgres.limits.soft or postgres.limits.hard }}
hard_limit: {{ postgres.limits.hard or postgres.limits.soft }}
soft_limit: {{ postgres.limits.soft }}
hard_limit: {{ postgres.limits.hard }}
- group: {{ postgres.group }}
{% endif %}

Expand Down
4 changes: 3 additions & 1 deletion postgres/dropped.sls
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ postgresql-removed:

postgres-dir-absent:
file.absent:
- name: {{ postgres.conf_dir }}
- names:
- {{ postgres.conf_dir }}
- {{ postgres.data_dir }}
10 changes: 10 additions & 0 deletions postgres/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@
),
base='postgres',
) %}

{# Concatenate the cluster preparation command and then append it to the `postgres` dict #}
{% set pc_cmd = '{0} {1}'.format(postgres.prepare_cluster.pgcommand, postgres.data_dir) %}
{% if postgres.cluster.locale %}
{% set pc_cmd = '{0} --locale={1}'.format(pc_cmd, postgres.cluster.locale) %}
{% endif %}
{% if postgres.cluster.encoding %}
{% set pc_cmd = '{0} --encoding={1}'.format(pc_cmd, postgres.cluster.encoding) %}
{% endif %}
{% do postgres.update({'prepare_cluster_cmd': pc_cmd}) %}
36 changes: 19 additions & 17 deletions postgres/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

Arch:
conf_dir: /var/lib/postgres/data
prepare_cluster:
command: initdb -D /var/lib/postgres/data
test: test -f /var/lib/postgres/data/PG_VERSION
data_dir: /var/lib/postgres/data
pkg_client: postgresql-libs
pkg_dev: postgresql

Expand All @@ -26,6 +24,8 @@ FreeBSD:
user: pgsql

OpenBSD:
conf_dir: /var/postgresql/data
data_dir: /var/postgresql/data
user: _postgresql

RedHat:
Expand All @@ -44,13 +44,10 @@ RedHat:
pkg_client: postgresql{{ release }}
pkg_libs: postgresql{{ release }}-libs
pkg_dev: postgresql{{ release }}-devel
conf_dir: /var/lib/pgsql/{{ repo.version }}/data
conf_dir: {{ data_dir }}
data_dir: {{ data_dir }}
service: postgresql-{{ repo.version }}

prepare_cluster:
command: initdb --pgdata='{{ data_dir }}'
test: test -f '{{ data_dir }}/PG_VERSION'

# Alternatives system
linux:
altpriority: 30
Expand Down Expand Up @@ -101,6 +98,11 @@ RedHat:

{% endif %}
pkg_libpq_dev: libpqxx-devel
pkg_dev_deps:
- perl-Time-HiRes
- libicu-devel
- perl-IPC-Run
- perl-Test-Simple

Suse:
pkg_repo:
Expand All @@ -113,20 +115,17 @@ Suse:
gpgautoimport: True

{% if repo.use_upstream_repo == true %}
{% set lib_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}
{% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}

fromrepo: pgdg-sles-{{ release }}
pkg: postgresql{{ release }}-server
pkg_client: postgresql{{ release }}
pkg_dev: postgresql{{ release }}-devel
pkg_libs: postgresql{{ release }}-libs
conf_dir: {{ lib_dir }}
conf_dir: {{ data_dir }}
data_dir: {{ data_dir }}
service: postgresql-{{ repo.version }}

prepare_cluster:
command: /usr/pgsql-{{ repo.version }}/bin/initdb --pgdata='{{ lib_dir }}'
test: test -f '{{ lib_dir }}/PG_VERSION'

# Alternatives system
linux:
altpriority: 30
Expand Down Expand Up @@ -162,7 +161,7 @@ Suse:
pkg_client: postgresql

{% endif %}
pkg_libpq_dev: libqpxx
pkg_libpq_dev: libpqxx

{%- if grains.os == 'MacOS' %}
## jinja check avoids rendering noise/failure on Linux
Expand All @@ -179,11 +178,14 @@ MacOS:
user: {{ repo.user }}
group: {{ repo.group }}
conf_dir: /Users/{{ repo.user }}/Library/AppSupport/postgres_{{ repo.use_upstream_repo }}
data_dir: /Users/{{ repo.user }}/Library/AppSupport/postgres_{{ repo.use_upstream_repo }}
prepare_cluster:
command: initdb -D /Users/{{ repo.user }}/Library/AppSupport/postgres_{{ repo.use_upstream_repo }}
test: test -f /Users/{{ repo.user }}/Library/AppSupport/postgres_{{ repo.use_upstream_repo }}/PG_VERSION
user: {{ repo.user }}
group: {{ repo.group }}
# macos limits
limits:
soft: 64000
hard: 64000
{%- endif %}

# vim: ft=sls
8 changes: 8 additions & 0 deletions postgres/python.sls
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{% from tpldir + "/map.jinja" import postgres with context %}

include:
- postgres.upstream

postgresql-python:
pkg.installed:
- name: {{ postgres.pkg_python}}
{% if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{% endif %}
{% if postgres.use_upstream_repo == true %}
- refresh: True
- require:
- pkgrepo: postgresql-repo
{% endif %}
5 changes: 3 additions & 2 deletions postgres/repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use_upstream_repo: {{ salt['pillar.get']('postgres:use_upstream_repo', defaults.postgres.use_upstream_repo) }}
version: {{ salt['pillar.get']('postgres:version', defaults.postgres.version) }}
fromrepo: {{ salt['pillar.get']('postgres:fromrepo', defaults.postgres.fromrepo) }}
cluster_name: {{ salt['pillar.get']('postgres:cluster:name', defaults.postgres.cluster.name) }}

#Early lookup for system user on MacOS
{% if grains.os == 'MacOS' %}
{% set sysuser = salt['pillar.get']('postgres.user') or salt['cmd.run']("stat -f '%Su' /dev/console") %}
{% set sysgroup = salt['pillar.get']('postgres.group') or salt['cmd.run']("stat -f '%Sg' /dev/console") %}
{% set sysuser = salt['pillar.get']('postgres:user', salt['cmd.run']("stat -f '%Su' /dev/console")) %}
{% set sysgroup = salt['pillar.get']('postgres:group', salt['cmd.run']("stat -f '%Sg' /dev/console")) %}
user: {{ sysuser }}
group: {{ sysgroup }}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions postgres/server/image.sls
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ include:

postgresql-start:
cmd.run:
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
- name: pg_ctl -D {{ postgres.data_dir }} -l logfile start
- runas: {{ postgres.user }}
- unless:
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
- ps -p $(head -n 1 {{ postgres.data_dir }}/postmaster.pid) 2>/dev/null
- require:
- file: postgresql-pg_hba

Expand Down
Loading