From cce4cbf992a94a059c09450d832f393c8ec5a80f Mon Sep 17 00:00:00 2001 From: Rob Ruana Date: Wed, 16 Jan 2019 04:39:30 +0000 Subject: [PATCH 1/3] Fix #236: Reload postgres service after ACL changes in pg_hba.conf * https://github.com/saltstack-formulas/postgres-formula/pull/216/commits/ef87358 --- postgres/server/init.sls | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/postgres/server/init.sls b/postgres/server/init.sls index 79fd44ee..12254c70 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -147,13 +147,6 @@ postgresql-conf: {%- endif %} -# Restart the service where reloading is not sufficient -# Currently when the cluster is created or changes made to `postgresql.conf` -postgresql-service-restart: - module.wait: - - name: service.restart - - m_name: {{ postgres.service }} - {%- set pg_hba_path = salt['file.join'](postgres.conf_dir, 'pg_hba.conf') %} postgresql-pg_hba: @@ -180,6 +173,15 @@ postgresql-pg_hba: {%- endif %} - require: - file: postgresql-config-dir + - watch_in: + - module: postgresql-service-restart + +# Restart the service where reloading is not sufficient +# Currently when the cluster is created or changes made to `postgresql.conf` +postgresql-service-restart: + module.wait: + - name: service.restart + - m_name: {{ postgres.service }} {%- set pg_ident_path = salt['file.join'](postgres.conf_dir, 'pg_ident.conf') %} From 0023ac30e32feee236ec96b7301c5a7ca2731fdb Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 16 Jan 2019 14:24:20 +0000 Subject: [PATCH 2/3] Move module `service.restart` to EOF and convert to `service.reload` * Simplify server restart/reload logic with respect to `MacOS` * Discussion in GitHub PR #250 --- postgres/server/init.sls | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/postgres/server/init.sls b/postgres/server/init.sls index 12254c70..51601bed 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -84,7 +84,7 @@ postgresql-cluster-prepared: - pkg: postgresql-server - file: postgresql-cluster-prepared - watch_in: - - module: postgresql-service-restart + - service: postgresql-running {%- endif %} postgresql-config-dir: @@ -143,7 +143,7 @@ postgresql-conf: - file: postgresql-conf-comment-port {%- endif %} - watch_in: - - module: postgresql-service-restart + - service: postgresql-running {%- endif %} @@ -174,14 +174,7 @@ postgresql-pg_hba: - require: - file: postgresql-config-dir - watch_in: - - module: postgresql-service-restart - -# Restart the service where reloading is not sufficient -# Currently when the cluster is created or changes made to `postgresql.conf` -postgresql-service-restart: - module.wait: - - name: service.restart - - m_name: {{ postgres.service }} + - service: postgresql-running {%- set pg_ident_path = salt['file.join'](postgres.conf_dir, 'pg_ident.conf') %} @@ -214,6 +207,12 @@ postgresql-pg_ident: {%- else %} - file: postgresql-cluster-prepared {%- endif %} + - watch_in: + {%- if grains.os not in ('MacOS',) %} + - module: postgresql-service-reload + {%- else %} + - service: postgresql-running + {%- endif %} {%- for name, tblspace in postgres.tablespaces|dictsort() %} @@ -258,15 +257,22 @@ postgresql-tablespace-dir-{{ name }}-fcontext: {%- if not postgres.bake_image %} # Start PostgreSQL server using OS init +# Note: This is also the target for numerous `watch_in` requisites above, used +# for the necessary service restart after changing the relevant configuration files postgresql-running: service.running: - name: {{ postgres.service }} - enable: True - {% if grains.os not in ('MacOS',) %} - - reload: True - {% endif %} - - watch: - - file: postgresql-pg_hba - - file: postgresql-pg_ident + +# Reload the service for changes made to `pg_ident.conf`, except for `MacOS` +# which is handled by `postgresql-running` above. +{%- if grains.os not in ('MacOS',) %} +postgresql-service-reload: + module.wait: + - name: service.reload + - m_name: {{ postgres.service }} + - require: + - service: postgresql-running +{%- endif %} {%- endif %} From 36f449dc7a517bc6cdb01c97b5635a8934d862a6 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 17 Jan 2019 16:29:44 +0000 Subject: [PATCH 3/3] Fix `mapping` list unpacking in `.format()` in `pg_ident` j2 template --- postgres/templates/pg_ident.conf.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/templates/pg_ident.conf.j2 b/postgres/templates/pg_ident.conf.j2 index 1d4696b8..cb6fd6fe 100644 --- a/postgres/templates/pg_ident.conf.j2 +++ b/postgres/templates/pg_ident.conf.j2 @@ -47,5 +47,5 @@ # MAPNAME SYSTEM-USERNAME PG-USERNAME {%- for mapping in mappings %} -{{ '{0:<15} {1:<22} {2}'.format(mapping) -}} +{{ '{0:<15} {1:<22} {2}'.format(*mapping) -}} {% endfor %}