Make clean state run by explicitly checking if init system is available

This commit is contained in:
Denys Havrysh 2017-01-06 16:37:07 +02:00
parent d4ed4be16e
commit 87f6cd880c
2 changed files with 25 additions and 19 deletions

View file

@ -88,17 +88,11 @@ postgresql-pg_hba:
- user: {{ postgres.user }} - user: {{ postgres.user }}
- group: {{ postgres.group }} - group: {{ postgres.group }}
- mode: 600 - mode: 600
- defaults:
acls: {{ postgres.acls }}
- require: - require:
- file: postgresql-config-dir - 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() %} {%- for name, tblspace in postgres.tablespaces|dictsort() %}
postgresql-tablespace-dir-{{ name }}: postgresql-tablespace-dir-{{ name }}:
@ -114,28 +108,42 @@ postgresql-tablespace-dir-{{ name }}:
{%- endfor %} {%- endfor %}
# An attempt to launch PostgreSQL with `pg_ctl` if service failed to start {%- if grains['init'] != 'unknown' %}
# with init system or Salt unable to load the `service` state module
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: postgresql-start:
cmd.run: cmd.run:
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start - name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
- runas: {{ postgres.user }} - runas: {{ postgres.user }}
- unless: - unless:
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null - 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. # 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 # The packages for other OS (i.e. `*.deb`) should do it automatically by default
postgresql-enable: postgresql-enable:
cmd.run: cmd.run:
{%- if salt['file.file_exists']('/bin/systemctl') %} {%- if salt['file.file_exists']('/bin/systemctl') %}
- name: systemctl enable {{ postgres.service }} - name: systemctl enable {{ postgres.service }}
{%- elif salt['cmd.which']('chkconfig') %} {%- elif salt['cmd.which']('chkconfig') %}
- name: chkconfig {{ postgres.service }} on - name: chkconfig {{ postgres.service }} on
{%- else %} {%- else %}
# Nothing to do # Nothing to do
- name: 'true' - name: 'true'
{%- endif %} {%- endif %}
- onchanges: - onchanges:
- cmd: postgresql-start - cmd: postgresql-start
{%- endif %}

View file

@ -1,5 +1,3 @@
{%- from "postgres/map.jinja" import postgres with context -%}
###################################################################### ######################################################################
# ATTENTION! Managed by SaltStack. # # ATTENTION! Managed by SaltStack. #
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN! # # 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 # TYPE DATABASE USER ADDRESS METHOD
{%- for acl in postgres.acls %} {%- for acl in acls %}
{%- if acl|first() == 'local' %} {%- if acl|first() == 'local' %}
{%- if acl|length() == 3 %} {%- if acl|length() == 3 %}