mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 01:30:25 +00:00
Use `bake_image
` Pillar setting to control PG startup behavior
This commit is contained in:
parent
d48f6f2a50
commit
186e972075
3 changed files with 24 additions and 10 deletions
|
@ -19,7 +19,7 @@ postgres:
|
|||
postgresconf: |
|
||||
listen_addresses = '*' # listen on all interfaces
|
||||
|
||||
# Backup extension for postgresql.conf file, defaults to `.bak`.
|
||||
# Backup extension for postgresql.conf file, defaults to ``.bak``.
|
||||
# Set to False to stop creation of backup on postgresql.conf changes.
|
||||
{%- if 'status.time' in salt.keys() %}
|
||||
postgresconf_backup: ".backup@{{ salt['status.time']('%y-%m-%d_%H:%M:%S') }}"
|
||||
|
@ -28,7 +28,7 @@ postgres:
|
|||
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver
|
||||
pg_hba.conf: salt://postgres/templates/pg_hba.conf.j2
|
||||
|
||||
# This section covers ACL management in the `pg_hba.conf` file.
|
||||
# This section covers ACL management in the ``pg_hba.conf`` file.
|
||||
# acls list controls: which hosts are allowed to connect, how clients
|
||||
# are authenticated, which PostgreSQL user names they can use, which
|
||||
# databases they can access. Records take one of these forms:
|
||||
|
@ -48,9 +48,20 @@ postgres:
|
|||
# PostgreSQL service name
|
||||
service: postgresql
|
||||
|
||||
{%- if grains['init'] == 'unknown' %}
|
||||
|
||||
# If Salt is unable to detect init system running in the scope of state run,
|
||||
# probably we are trying to bake a container/VM image with PostgreSQL.
|
||||
# Use ``service`` setting to contol how PostgreSQL will be started: if set to
|
||||
# ``True`` the raw ``pg_ctl`` will be utilized instead of packaged init
|
||||
# script, job or unit run with Salt ``service`` state.
|
||||
bake_image: True
|
||||
|
||||
{%- endif %}
|
||||
|
||||
# Create/remove users, tablespaces, databases, schema and extensions.
|
||||
# Each of these dictionaries contains PostgreSQL entities which
|
||||
# mapped to the `postgres_*` Salt states with arguments. See the Salt
|
||||
# mapped to the ``postgres_*`` Salt states with arguments. See the Salt
|
||||
# documentaion to get all supported argument for a particular state.
|
||||
#
|
||||
# Format is the following:
|
||||
|
|
|
@ -33,6 +33,8 @@ postgres:
|
|||
|
||||
service: postgresql
|
||||
|
||||
bake_image: False
|
||||
|
||||
users: {}
|
||||
tablespaces: {}
|
||||
databases: {}
|
||||
|
|
|
@ -108,7 +108,9 @@ postgresql-tablespace-dir-{{ name }}:
|
|||
|
||||
{%- endfor %}
|
||||
|
||||
{%- if grains['init'] != 'unknown' %}
|
||||
{%- if not postgres.bake_image %}
|
||||
|
||||
# Start PostgreSQL server using OS init
|
||||
|
||||
postgresql-running:
|
||||
service.running:
|
||||
|
@ -120,8 +122,7 @@ postgresql-running:
|
|||
|
||||
{%- else %}
|
||||
|
||||
# An attempt to launch PostgreSQL with `pg_ctl` if Salt was unable to
|
||||
# detect local init system (`service` module would fail in this case)
|
||||
# An attempt to launch PostgreSQL with `pg_ctl` during an image preparation
|
||||
|
||||
postgresql-start:
|
||||
cmd.run:
|
||||
|
@ -129,10 +130,10 @@ postgresql-start:
|
|||
- runas: {{ postgres.user }}
|
||||
- unless:
|
||||
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
|
||||
- require:
|
||||
- file: postgresql-pg_hba
|
||||
|
||||
# Try to enable PostgreSQL in "manual" way if Salt `service` state module
|
||||
# is currently not available (e.g. during Docker or Packer build when is no init
|
||||
# system running)
|
||||
# Try to enable PostgreSQL in "manual" way when baking an image
|
||||
|
||||
postgresql-enable:
|
||||
cmd.run:
|
||||
|
@ -146,7 +147,7 @@ postgresql-enable:
|
|||
# Nothing to do
|
||||
- name: 'true'
|
||||
{%- endif %}
|
||||
- onchanges:
|
||||
- require:
|
||||
- cmd: postgresql-start
|
||||
|
||||
{%- endif %}
|
||||
|
|
Loading…
Add table
Reference in a new issue