Skip to content

Allow configuration of cluster name, locale & encoding #232

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 4 commits into from
Jun 28, 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
7 changes: 7 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ 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
Expand Down
9 changes: 5 additions & 4 deletions postgres/codenamemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
{% else %}
{% set fromrepo = name %}
{% endif %}
{% set conf_dir = '/etc/postgresql/' ~ version ~ '/main' %}
{% set data_dir = '/var/lib/postgresql/' ~ version ~ '/main' %}
{% 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'
name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main'
pkg: postgresql-{{ version }}
pkg_client: postgresql-client-{{ version }}
prepare_cluster:
pgcommand: pg_createcluster {{ version }} main -d
pgcommand: pg_createcluster {{ version }} {{ cluster_name }} -d
user: root

{% endmacro %}
Expand Down
5 changes: 5 additions & 0 deletions postgres/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ postgres:
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'
Expand Down
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}) %}
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', salt['cmd.run']("stat -f '%Su' /dev/console")) %}
{% set sysgroup = salt['pillar.get']('postgres.group', salt['cmd.run']("stat -f '%Sg' /dev/console")) %}
{% set sysuser = salt['pillar.get']('postgres:user', salt['cmd.run']("stat -f '%Su' /dev/console")) %}
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch.

{% set sysgroup = salt['pillar.get']('postgres:group', salt['cmd.run']("stat -f '%Sg' /dev/console")) %}
user: {{ sysuser }}
group: {{ sysgroup }}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ postgresql-cluster-prepared:
- name: {{ postgres.prepare_cluster.command }}
- unless: {{ postgres.prepare_cluster.test }}
{%- else %}
- name: {{ postgres.prepare_cluster.pgcommand }} {{ postgres.data_dir }}
- name: {{ postgres.prepare_cluster_cmd }}
- unless: test -f {{ postgres.data_dir }}/{{ postgres.prepare_cluster.pgtestfile }}
{%- endif %}
- cwd: /
Expand Down