Fix #236: Restart postgres service after ACL changes in pg_hba.conf#250
Fix #236: Restart postgres service after ACL changes in pg_hba.conf#250aboe76 merged 3 commits intosaltstack-formulas:masterfrom
Conversation
vutny
left a comment
There was a problem hiding this comment.
Hi @myii !
Thanks for your PR. The logic in the formula around restarting/reloading the service remains quite complex.
I have few suggestions:
- First you need to remove the requisite for
postgresql-pg_hbafrompostgresql-runningstate. It becomes excrescent. Also, a restarting is mandatory onMacOSanyway, so you might need to check that. - Better to move the restarting state at the bottom of the SLS file. There are SELinux related states below the current position. And when you restart the service early, later
postgresql-runningstate will not take changes and the tablespaces could not be accessed. - This is optional, but you may think about restarting PostgreSQL only when it is actually running before attempting to make a cold start. This way you avoid starting and immediate restarting during initial state run or when the cluster was shut down.
The
|
@vutny Thanks for the prompt review and feedback -- excellent again, as usual. Discussion about commit addedI've added another commit to the PR to address the issues you've raised. But don't merge this yet -- I've added it primarily for discussion on how best to move forwards with this. Let me start by replying point by point.
I believe we can address and resolve this by criticising the commit I've just added. I say that because I implemented each sub-issue in the most direct manner, in order to help highlight the overlapping logic.
Considerations moving forwardCurrent logic (after this commit)
Proposed logicKey change:
Leading to:
|
|
@vutny Leaving the first commit as-is (i.e. commit by @RobRuana), suggesting something like the following: @@ -84,7 +84,7 @@
- pkg: postgresql-server
- file: postgresql-cluster-prepared
- watch_in:
- - module: postgresql-service-restart
+ - service: postgresql-running
{%- endif %}
postgresql-config-dir:
@@ -143,7 +143,7 @@
- file: postgresql-conf-comment-port
{%- endif %}
- watch_in:
- - module: postgresql-service-restart
+ - service: postgresql-running
{%- endif %}
@@ -174,14 +174,7 @@
- require:
- file: postgresql-config-dir
- watch_in:
- - module: postgresql-service-restart
+ - service: postgresql-running
-
-# 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') %}
@@ -214,6 +207,12 @@
{%- 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() %}
@@ -262,11 +261,14 @@
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
+
+{%- if grains.os not in ('MacOS',) %}
+postgresql-service-reload:
+ module.wait:
+ - name: service.reload
+ - m_name: {{ postgres.service }}
+ - require:
+ - service: postgresql-running
+{%- endif %}Edit: Minimised some of the |
|
Thanks for picking this up and running with it! |
|
@RobRuana You're welcome. Thanks for responding, nice to know that you're OK with it. Don't hesitate to shout if you see anything going awry. |
@vutny Great -- so my plan is to rebase this as the second commit to lose the one that I used to "explain things". Meaning, two commits in this PR altogether:
So we're agreed to change the module |
This is a right thing to do. |
|
@vutny OK, I'll rebase and push within the next few minutes. Thanks again for reviewing. |
* Simplify server restart/reload logic with respect to `MacOS` * Discussion in GitHub PR saltstack-formulas#250
|
@vutny OK, have pushed to replace the previous second commit. Let me know if all OK. Thanks. |
|
@vutny Found a separate problem while testing but a small fix so added another commit here. Using the postgres-formula/pillar.example Lines 78 to 80 in c213b30 Resulted in an error: Comment: Unable to manage file: Jinja error: unsupported format string passed to list.__format__
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 380, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/usr/lib/python3/dist-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 50, in top-level template code
TypeError: unsupported format string passed to list.__format__
; line 50
---
[...]
# ----------------------------------
# MAPNAME SYSTEM-USERNAME PG-USERNAME
{%- for mapping in mappings %}
{{ '{0:<15} {1:<22} {2}'.format(mapping) -}} <======================
{% endfor %}
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 380, in render_jinja_tmpl
output = template.render(**decoded_context)
[...]So fixed the |
|
@vutny You're welcome -- wouldn't have even considered making these extra changes if it wasn't for your excellent feedback. |
|
You got my approval @aboe76 . |
|
@myii merged it |
|
@aboe76 Thanks, appreciate it. |
NOTE: This [first commit] is not my work.
In #236 (comment), I specifically mentioned that this solution was provided by @RobRuana in #216. The specific commit:
I noticed that this issue was still open, so I have set @RobRuana as the author of the commit in an attempt to resolve this issue as well as attribute it accordingly. If this is inappropriate in any way, I am most happy to close this PR.