mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-15 17:20:25 +00:00
Make clean state run by explicitly checking if init system is available
This commit is contained in:
parent
d4ed4be16e
commit
87f6cd880c
2 changed files with 25 additions and 19 deletions
|
@ -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 %}
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Add table
Reference in a new issue