From 87f6cd880ca637984268e3bbe4ef7078f47ced08 Mon Sep 17 00:00:00 2001 From: Denys Havrysh Date: Fri, 6 Jan 2017 16:37:07 +0200 Subject: [PATCH] Make clean state run by explicitly checking if init system is available --- postgres/server.sls | 40 ++++++++++++++++++------------- postgres/templates/pg_hba.conf.j2 | 4 +--- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/postgres/server.sls b/postgres/server.sls index e92ea3f..3c1c170 100644 --- a/postgres/server.sls +++ b/postgres/server.sls @@ -88,17 +88,11 @@ postgresql-pg_hba: - user: {{ postgres.user }} - group: {{ postgres.group }} - mode: 600 + - defaults: + acls: {{ postgres.acls }} - require: - file: postgresql-config-dir -postgresql-running: - service.running: - - name: {{ postgres.service }} - - enable: True - - reload: True - - watch: - - file: postgresql-pg_hba - {%- for name, tblspace in postgres.tablespaces|dictsort() %} postgresql-tablespace-dir-{{ name }}: @@ -114,28 +108,42 @@ postgresql-tablespace-dir-{{ name }}: {%- endfor %} -# An attempt to launch PostgreSQL with `pg_ctl` if service failed to start -# with init system or Salt unable to load the `service` state module +{%- if grains['init'] != 'unknown' %} + +postgresql-running: + service.running: + - name: {{ postgres.service }} + - enable: True + - reload: True + - watch: + - file: postgresql-pg_hba + +{%- else %} + +# An attempt to launch PostgreSQL with `pg_ctl` if Salt was unable to +# detect local init system (`service` module would fail in this case) + postgresql-start: cmd.run: - name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start - runas: {{ postgres.user }} - unless: - ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null - - onfail: - - service: postgresql-running # Try to enable PostgreSQL in "manual" way for systemd and RedHat-based distros. # The packages for other OS (i.e. `*.deb`) should do it automatically by default + postgresql-enable: cmd.run: -{%- if salt['file.file_exists']('/bin/systemctl') %} + {%- if salt['file.file_exists']('/bin/systemctl') %} - name: systemctl enable {{ postgres.service }} -{%- elif salt['cmd.which']('chkconfig') %} + {%- elif salt['cmd.which']('chkconfig') %} - name: chkconfig {{ postgres.service }} on -{%- else %} + {%- else %} # Nothing to do - name: 'true' -{%- endif %} + {%- endif %} - onchanges: - cmd: postgresql-start + +{%- endif %} diff --git a/postgres/templates/pg_hba.conf.j2 b/postgres/templates/pg_hba.conf.j2 index 560c45e..11f4cad 100644 --- a/postgres/templates/pg_hba.conf.j2 +++ b/postgres/templates/pg_hba.conf.j2 @@ -1,5 +1,3 @@ -{%- from "postgres/map.jinja" import postgres with context -%} - ###################################################################### # ATTENTION! Managed by SaltStack. # # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN! # @@ -22,7 +20,7 @@ local all postgres peer # TYPE DATABASE USER ADDRESS METHOD -{%- for acl in postgres.acls %} +{%- for acl in acls %} {%- if acl|first() == 'local' %} {%- if acl|length() == 3 %}