Skip to content

Commit 844ae97

Browse files
authored
Merge pull request #218 from myii/PR_port
Allow `port` to be configurable
2 parents 0c6f9a4 + 79ab1a2 commit 844ae97

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

pillar.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Port to use for the cluster -- can be used to provide a non-standard port
2+
# NOTE: If already set in the minion config, that value takes priority
3+
postgres.port: '5432'
4+
15
postgres:
26
# UPSTREAM REPO
37
# Set True to configure upstream postgresql.org repository for YUM/APT/ZYPP
@@ -34,7 +38,7 @@ postgres:
3438
# POSTGRES
3539
# Append the lines under this item to your postgresql.conf file.
3640
# Pay attention to indent exactly with 4 spaces for all lines.
37-
postgresconf: |
41+
postgresconf: |-
3842
listen_addresses = '*' # listen on all interfaces
3943
4044
# Path to the `pg_hba.conf` file Jinja template on Salt Fileserver

postgres/server/init.sls

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,50 @@ postgresql-config-dir:
8686
- require:
8787
- cmd: postgresql-cluster-prepared
8888
89-
{%- if postgres.postgresconf %}
89+
{%- set db_port = salt['config.option']('postgres.port') %}
90+
{%- if db_port %}
91+
92+
postgresql-conf-comment-port:
93+
file.comment:
94+
- name: {{ postgres.conf_dir }}/postgresql.conf
95+
- regex: ^port\s*=.+
96+
- require:
97+
- file: postgresql-config-dir
98+
99+
{%- endif %}
100+
101+
{%- if postgres.postgresconf or db_port %}
90102
91103
postgresql-conf:
92104
file.blockreplace:
93105
- name: {{ postgres.conf_dir }}/postgresql.conf
94106
- marker_start: "# Managed by SaltStack: listen_addresses: please do not edit"
95107
- marker_end: "# Managed by SaltStack: end of salt managed zone --"
96108
- content: |
109+
{%- if postgres.postgresconf %}
97110
{{ postgres.postgresconf|indent(8) }}
111+
{%- endif %}
112+
{%- if db_port %}
113+
port = {{ db_port }}
114+
{%- endif %}
98115
- show_changes: True
99116
- append_if_not_found: True
100117
{#- Detect empty values (none, '') in the config_backup #}
101118
- backup: {{ postgres.config_backup|default(false, true) }}
102119
- require:
103120
- file: postgresql-config-dir
121+
{%- if db_port %}
122+
- file: postgresql-conf-comment-port
123+
{%- endif %}
104124
- watch_in:
105-
- service: postgresql-running
125+
- module: postgresql-service-restart
126+
127+
# Restart the service where reloading is not sufficient
128+
# Currently only when changes are made to `postgresql.conf`
129+
postgresql-service-restart:
130+
module.wait:
131+
- name: service.restart
132+
- m_name: {{ postgres.service }}
106133
107134
{%- endif %}
108135

0 commit comments

Comments
 (0)