diff --git a/pillar.example b/pillar.example index 48d0e07..ec11cdc 100644 --- a/pillar.example +++ b/pillar.example @@ -32,6 +32,10 @@ postgres: hard: 64000 # POSTGRES + # Non-standard port to use for the cluster + # Only set if port `5432` is not appropriate + port: 5433 + # Append the lines under this item to your postgresql.conf file. # Pay attention to indent exactly with 4 spaces for all lines. postgresconf: | diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index f84ba3d..4d50d32 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -3,6 +3,7 @@ postgres: use_upstream_repo: True version: '9.5' + default_port: 5432 pkg: postgresql pkgs_extra: [] pkg_client: postgresql-client diff --git a/postgres/macros.jinja b/postgres/macros.jinja index 4eedddb..e530b11 100644 --- a/postgres/macros.jinja +++ b/postgres/macros.jinja @@ -23,6 +23,7 @@ {{ state }}-{{ name }}: {{ state }}.{{ ensure|default('present') }}: {{- format_kwargs(kwarg) }} + - db_port: {{ postgres.port|default(postgres.default_port) }} - onchanges: - test: postgres-reload-modules diff --git a/postgres/server/init.sls b/postgres/server/init.sls index ace913d..d41775b 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -192,3 +192,24 @@ postgresql-running: - file: postgresql-pg_ident {%- endif %} + +{%- if postgres.port|default(false) %} + +postgresql-port: + file.replace: + - name: {{ postgres.conf_dir }}/postgresql.conf + - pattern: ^#*\s*(port)\s*=\s*\d{4,5}(.*)$ + - repl: \1 = {{ postgres.port }}\2 + - flags: 8 # ['MULTILINE'] + - show_changes: True + - append_if_not_found: True + - backup: {{ postgres.config_backup|default(false, true) }} + - require: + - file: postgresql-config-dir + - watch_in: + - service: postgresql-port + + service.running: + - name: {{ postgres.service }} + +{%- endif %}