mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-15 17:20:25 +00:00
Attempt to start and manage PostgreSQL service even if init system fails
This commit is contained in:
parent
80077169ce
commit
d4ed4be16e
6 changed files with 53 additions and 101 deletions
|
@ -31,7 +31,6 @@
|
|||
command: pg_createcluster {{ version }} main
|
||||
test: test -f /var/lib/postgresql/{{ version }}/main/PG_VERSION && test -f /etc/postgresql/{{ version }}/main/postgresql.conf
|
||||
user: root
|
||||
env: {}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
|
|
|
@ -12,15 +12,10 @@ postgres:
|
|||
user: postgres
|
||||
group: postgres
|
||||
|
||||
# if prepare_cluster is over-ridden in any of:
|
||||
# - osmap.yaml
|
||||
# - oscodenamemap.yaml
|
||||
# - osfingermap.yaml
|
||||
# you will have to specify a complete dictionary.
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: service postgresql initdb
|
||||
command: initdb --pgdata=/var/lib/pgsql/data
|
||||
test: test -f /var/lib/pgsql/data/PG_VERSION
|
||||
user: postgres
|
||||
env: {}
|
||||
|
||||
conf_dir: /var/lib/pgsql/data
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
||||
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
||||
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
||||
{% import_yaml "postgres/osmajorreleasemap.yaml" as osmajorreleasemap %}
|
||||
|
||||
{% set postgres = salt['grains.filter_by'](
|
||||
defaults,
|
||||
|
@ -11,11 +10,7 @@
|
|||
merge=salt['grains.filter_by'](
|
||||
oscodenamemap,
|
||||
grain='oscodename',
|
||||
merge=salt['grains.filter_by'](
|
||||
osmajorreleasemap,
|
||||
grain='osmajorrelease',
|
||||
merge=salt['pillar.get']('postgres', {}),
|
||||
),
|
||||
merge=salt['pillar.get']('postgres', {}),
|
||||
),
|
||||
),
|
||||
base='postgres',
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
{% import_yaml "postgres/repo.yaml" as repo %}
|
||||
|
||||
{% if grains['os_family'] == 'RedHat' %}
|
||||
|
||||
### RedHat releases
|
||||
|
||||
{% if repo.use_upstream_repo %}
|
||||
|
||||
{% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}
|
||||
|
||||
# PostgreSQL from upstream repository
|
||||
|
||||
default:
|
||||
prepare_cluster:
|
||||
user: postgres
|
||||
command: /usr/pgsql-{{ repo.version }}/bin/initdb -D {{ data_dir }}
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
'6':
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: service postgresql-{{ repo.version }} initdb
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
'7':
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: /usr/pgsql-{{ repo.version }}/bin/postgresql95-setup initdb
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% set data_dir = '/var/lib/pgsql/data' %}
|
||||
|
||||
# PostgreSQL from OS repositories
|
||||
|
||||
default:
|
||||
prepare_cluster:
|
||||
user: postgres
|
||||
command: initdb -D {{ data_dir }}
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
'6':
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: service postgresql initdb
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
'7':
|
||||
prepare_cluster:
|
||||
user: root
|
||||
command: postgresql-setup initdb
|
||||
test: test -f {{ data_dir }}/PG_VERSION
|
||||
env: {}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
|
||||
### Empty YAML, no settings for other OS
|
||||
|
||||
{}
|
||||
|
||||
{% endif %}
|
||||
|
||||
# vim: ft=sls
|
|
@ -5,10 +5,8 @@
|
|||
Arch:
|
||||
conf_dir: /var/lib/postgres/data
|
||||
prepare_cluster:
|
||||
user: postgres
|
||||
command: initdb -D /var/lib/postgresql/data
|
||||
test: test -f /var/lib/postgres/data/PG_VERSION
|
||||
env: {}
|
||||
pkg_client: postgresql
|
||||
pkg_dev: postgresql
|
||||
|
||||
|
@ -37,11 +35,17 @@ RedHat:
|
|||
|
||||
{% if repo.use_upstream_repo %}
|
||||
|
||||
{% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}
|
||||
|
||||
pkg: postgresql{{ release }}-server
|
||||
pkg_client: postgresql{{ release }}
|
||||
conf_dir: /var/lib/pgsql/{{ repo.version }}/data
|
||||
service: postgresql-{{ repo.version }}
|
||||
|
||||
prepare_cluster:
|
||||
command: initdb --pgdata='{{ data_dir }}'
|
||||
test: test -f '{{ data_dir }}/PG_VERSION'
|
||||
|
||||
# Directory containing PostgreSQL client executables
|
||||
bin_dir: /usr/pgsql-{{ repo.version }}/bin
|
||||
client_bins:
|
||||
|
|
|
@ -20,6 +20,27 @@ postgresql-server:
|
|||
- pkgrepo: postgresql-repo
|
||||
{%- endif %}
|
||||
|
||||
{%- if 'bin_dir' in postgres %}
|
||||
|
||||
# Make server binaries available in $PATH
|
||||
|
||||
{%- for bin in postgres.server_bins %}
|
||||
|
||||
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}
|
||||
|
||||
{{ bin }}:
|
||||
alternatives.install:
|
||||
- link: {{ salt['file.join']('/usr/bin', bin) }}
|
||||
- path: {{ path }}
|
||||
- priority: 30
|
||||
- onlyif: test -f {{ path }}
|
||||
- require:
|
||||
- pkg: postgresql-server
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
{%- endif %}
|
||||
|
||||
postgresql-cluster-prepared:
|
||||
cmd.run:
|
||||
- name: {{ postgres.prepare_cluster.command }}
|
||||
|
@ -93,23 +114,28 @@ postgresql-tablespace-dir-{{ name }}:
|
|||
|
||||
{%- endfor %}
|
||||
|
||||
{%- if 'bin_dir' in postgres %}
|
||||
|
||||
# Make server binaries available in $PATH
|
||||
|
||||
{%- for bin in postgres.server_bins %}
|
||||
|
||||
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}
|
||||
|
||||
{{ bin }}:
|
||||
alternatives.install:
|
||||
- link: {{ salt['file.join']('/usr/bin', bin) }}
|
||||
- path: {{ path }}
|
||||
- priority: 30
|
||||
- onlyif: test -f {{ path }}
|
||||
- require:
|
||||
- pkg: postgresql-server
|
||||
|
||||
{%- 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
|
||||
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') %}
|
||||
- name: systemctl enable {{ postgres.service }}
|
||||
{%- elif salt['cmd.which']('chkconfig') %}
|
||||
- name: chkconfig {{ postgres.service }} on
|
||||
{%- else %}
|
||||
# Nothing to do
|
||||
- name: 'true'
|
||||
{%- endif %}
|
||||
- onchanges:
|
||||
- cmd: postgresql-start
|
||||
|
|
Loading…
Add table
Reference in a new issue