Skip to content

Commit 87f6cd8

Browse files
committed
Make clean state run by explicitly checking if init system is available
1 parent d4ed4be commit 87f6cd8

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

postgres/server.sls

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@ postgresql-pg_hba:
8888
- user: {{ postgres.user }}
8989
- group: {{ postgres.group }}
9090
- mode: 600
91+
- defaults:
92+
acls: {{ postgres.acls }}
9193
- require:
9294
- file: postgresql-config-dir
9395
94-
postgresql-running:
95-
service.running:
96-
- name: {{ postgres.service }}
97-
- enable: True
98-
- reload: True
99-
- watch:
100-
- file: postgresql-pg_hba
101-
10296
{%- for name, tblspace in postgres.tablespaces|dictsort() %}
10397
10498
postgresql-tablespace-dir-{{ name }}:
@@ -114,28 +108,42 @@ postgresql-tablespace-dir-{{ name }}:
114108
115109
{%- endfor %}
116110
117-
# An attempt to launch PostgreSQL with `pg_ctl` if service failed to start
118-
# with init system or Salt unable to load the `service` state module
111+
{%- if grains['init'] != 'unknown' %}
112+
113+
postgresql-running:
114+
service.running:
115+
- name: {{ postgres.service }}
116+
- enable: True
117+
- reload: True
118+
- watch:
119+
- file: postgresql-pg_hba
120+
121+
{%- else %}
122+
123+
# An attempt to launch PostgreSQL with `pg_ctl` if Salt was unable to
124+
# detect local init system (`service` module would fail in this case)
125+
119126
postgresql-start:
120127
cmd.run:
121128
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
122129
- runas: {{ postgres.user }}
123130
- unless:
124131
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
125-
- onfail:
126-
- service: postgresql-running
127132
128133
# Try to enable PostgreSQL in "manual" way for systemd and RedHat-based distros.
129134
# The packages for other OS (i.e. `*.deb`) should do it automatically by default
135+
130136
postgresql-enable:
131137
cmd.run:
132-
{%- if salt['file.file_exists']('/bin/systemctl') %}
138+
{%- if salt['file.file_exists']('/bin/systemctl') %}
133139
- name: systemctl enable {{ postgres.service }}
134-
{%- elif salt['cmd.which']('chkconfig') %}
140+
{%- elif salt['cmd.which']('chkconfig') %}
135141
- name: chkconfig {{ postgres.service }} on
136-
{%- else %}
142+
{%- else %}
137143
# Nothing to do
138144
- name: 'true'
139-
{%- endif %}
145+
{%- endif %}
140146
- onchanges:
141147
- cmd: postgresql-start
148+
149+
{%- endif %}

postgres/templates/pg_hba.conf.j2

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{%- from "postgres/map.jinja" import postgres with context -%}
2-
31
######################################################################
42
# ATTENTION! Managed by SaltStack. #
53
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN! #
@@ -22,7 +20,7 @@ local all postgres peer
2220

2321
# TYPE DATABASE USER ADDRESS METHOD
2422

25-
{%- for acl in postgres.acls %}
23+
{%- for acl in acls %}
2624
{%- if acl|first() == 'local' %}
2725

2826
{%- if acl|length() == 3 %}

0 commit comments

Comments
 (0)