Skip to content

Allow conf/data directory separation #228

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 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions postgres/codenamemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@

{% 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 conf_dir = '/etc/postgresql/' ~ version ~ '/main' %}
{% set data_dir = '/var/lib/postgresql/' ~ version ~ '/main' %}

{{ codename|default(name, true) }}:
# PostgreSQL packages are mostly downloaded from `main` repo component
conf_dir: {{ conf_dir }}
data_dir: {{ data_dir }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these values become global for all Debian derivatives, we should move them to the OS family map.

Copy link
Contributor Author

@noelmcloughlin noelmcloughlin Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version calculated by oscodename is passed to fedora_codename macro and used ..

  {% set conf_dir = '/etc/postgresql/' + version|string + '/main' %}
  {% set data_dir = '/var/lib/postgresql/' + version|string + '/main' %}

If version calculated by OS map is different to version calculated here, problems will result? What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right, absolutely. I've completely forgot that the version for distro-provided packages is handled here as well. Thanks, keep insisting on right things! 👍

fromrepo: {{ fromrepo }}
pkg_repo:
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 }} main -d
user: root

{% endmacro %}
Expand All @@ -38,15 +39,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: {{ fromrepo }}
pkg_repo:
baseurl: 'https://download.postgresql.org/pub/repos/yum/{{ version }}/fedora/fedora-$releasever-$basearch'

Expand Down
5 changes: 3 additions & 2 deletions postgres/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ 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: []

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

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 }}
25 changes: 9 additions & 16 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 @@ -118,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 @@ -184,9 +178,8 @@ 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 }}
{%- 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
28 changes: 22 additions & 6 deletions postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,43 @@ postgresql-{{ bin }}-altinstall:
{%- endif %}

postgresql-cluster-prepared:
file.directory:
- name: {{ postgres.conf_dir }}
- user: {{ postgres.user }}
- group: {{ postgres.group }}
- makedirs: True
- recurse:
- user
- group
- dir_mode: 755
cmd.run:
{%- if postgres.prepare_cluster.command is defined %}
{# support for depreciated 'prepare_cluster.command' pillar #}
- name: {{ postgres.prepare_cluster.command }}
- unless: {{ postgres.prepare_cluster.test }}
{%- else %}
- name: {{ postgres.prepare_cluster.pgcommand }} {{ postgres.data_dir }}
- unless: test -f {{ postgres.data_dir }}/{{ postgres.prepare_cluster.pgtestfile }}
{%- endif %}
- cwd: /
- runas: {{ postgres.prepare_cluster.user }}
- env: {{ postgres.prepare_cluster.env }}
- unless:
- {{ postgres.prepare_cluster.test }}
- runas: {{ postgres.user }}
- require:
- pkg: postgresql-server
- file: postgresql-cluster-prepared

postgresql-config-dir:
file.directory:
- name: {{ postgres.conf_dir }}
- names:
- {{ postgres.data_dir }}
- {{ postgres.conf_dir }}
- user: {{ postgres.user }}
- group: {{ postgres.group }}
- dir_mode: {{ postgres.conf_dir_mode }}
- force: True
- file_mode: 644
- recurse:
- user
- group
- mode
- makedirs: True
- require:
- cmd: postgresql-cluster-prepared
Expand Down