Attempt to start and manage PostgreSQL service even if init system fails
This commit is contained in:
@@ -31,7 +31,6 @@
|
|||||||
command: pg_createcluster {{ version }} main
|
command: pg_createcluster {{ version }} main
|
||||||
test: test -f /var/lib/postgresql/{{ version }}/main/PG_VERSION && test -f /etc/postgresql/{{ version }}/main/postgresql.conf
|
test: test -f /var/lib/postgresql/{{ version }}/main/PG_VERSION && test -f /etc/postgresql/{{ version }}/main/postgresql.conf
|
||||||
user: root
|
user: root
|
||||||
env: {}
|
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,10 @@ postgres:
|
|||||||
user: postgres
|
user: postgres
|
||||||
group: 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:
|
prepare_cluster:
|
||||||
user: root
|
command: initdb --pgdata=/var/lib/pgsql/data
|
||||||
command: service postgresql initdb
|
|
||||||
test: test -f /var/lib/pgsql/data/PG_VERSION
|
test: test -f /var/lib/pgsql/data/PG_VERSION
|
||||||
|
user: postgres
|
||||||
env: {}
|
env: {}
|
||||||
|
|
||||||
conf_dir: /var/lib/pgsql/data
|
conf_dir: /var/lib/pgsql/data
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
{% import_yaml "postgres/defaults.yaml" as defaults %}
|
||||||
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
{% import_yaml "postgres/osmap.yaml" as osmap %}
|
||||||
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
{% import_yaml "postgres/codenamemap.yaml" as oscodenamemap %}
|
||||||
{% import_yaml "postgres/osmajorreleasemap.yaml" as osmajorreleasemap %}
|
|
||||||
|
|
||||||
{% set postgres = salt['grains.filter_by'](
|
{% set postgres = salt['grains.filter_by'](
|
||||||
defaults,
|
defaults,
|
||||||
@@ -11,12 +10,8 @@
|
|||||||
merge=salt['grains.filter_by'](
|
merge=salt['grains.filter_by'](
|
||||||
oscodenamemap,
|
oscodenamemap,
|
||||||
grain='oscodename',
|
grain='oscodename',
|
||||||
merge=salt['grains.filter_by'](
|
|
||||||
osmajorreleasemap,
|
|
||||||
grain='osmajorrelease',
|
|
||||||
merge=salt['pillar.get']('postgres', {}),
|
merge=salt['pillar.get']('postgres', {}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
base='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:
|
Arch:
|
||||||
conf_dir: /var/lib/postgres/data
|
conf_dir: /var/lib/postgres/data
|
||||||
prepare_cluster:
|
prepare_cluster:
|
||||||
user: postgres
|
|
||||||
command: initdb -D /var/lib/postgresql/data
|
command: initdb -D /var/lib/postgresql/data
|
||||||
test: test -f /var/lib/postgres/data/PG_VERSION
|
test: test -f /var/lib/postgres/data/PG_VERSION
|
||||||
env: {}
|
|
||||||
pkg_client: postgresql
|
pkg_client: postgresql
|
||||||
pkg_dev: postgresql
|
pkg_dev: postgresql
|
||||||
|
|
||||||
@@ -37,11 +35,17 @@ RedHat:
|
|||||||
|
|
||||||
{% if repo.use_upstream_repo %}
|
{% if repo.use_upstream_repo %}
|
||||||
|
|
||||||
|
{% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}
|
||||||
|
|
||||||
pkg: postgresql{{ release }}-server
|
pkg: postgresql{{ release }}-server
|
||||||
pkg_client: postgresql{{ release }}
|
pkg_client: postgresql{{ release }}
|
||||||
conf_dir: /var/lib/pgsql/{{ repo.version }}/data
|
conf_dir: /var/lib/pgsql/{{ repo.version }}/data
|
||||||
service: postgresql-{{ repo.version }}
|
service: postgresql-{{ repo.version }}
|
||||||
|
|
||||||
|
prepare_cluster:
|
||||||
|
command: initdb --pgdata='{{ data_dir }}'
|
||||||
|
test: test -f '{{ data_dir }}/PG_VERSION'
|
||||||
|
|
||||||
# Directory containing PostgreSQL client executables
|
# Directory containing PostgreSQL client executables
|
||||||
bin_dir: /usr/pgsql-{{ repo.version }}/bin
|
bin_dir: /usr/pgsql-{{ repo.version }}/bin
|
||||||
client_bins:
|
client_bins:
|
||||||
|
|||||||
@@ -20,6 +20,27 @@ postgresql-server:
|
|||||||
- pkgrepo: postgresql-repo
|
- pkgrepo: postgresql-repo
|
||||||
{%- endif %}
|
{%- 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:
|
postgresql-cluster-prepared:
|
||||||
cmd.run:
|
cmd.run:
|
||||||
- name: {{ postgres.prepare_cluster.command }}
|
- name: {{ postgres.prepare_cluster.command }}
|
||||||
@@ -93,23 +114,28 @@ postgresql-tablespace-dir-{{ name }}:
|
|||||||
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
{%- if 'bin_dir' in postgres %}
|
# 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
|
||||||
# Make server binaries available in $PATH
|
postgresql-start:
|
||||||
|
cmd.run:
|
||||||
{%- for bin in postgres.server_bins %}
|
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
|
||||||
|
- runas: {{ postgres.user }}
|
||||||
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}
|
- unless:
|
||||||
|
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
|
||||||
{{ bin }}:
|
- onfail:
|
||||||
alternatives.install:
|
- service: postgresql-running
|
||||||
- link: {{ salt['file.join']('/usr/bin', bin) }}
|
|
||||||
- path: {{ path }}
|
|
||||||
- priority: 30
|
|
||||||
- onlyif: test -f {{ path }}
|
|
||||||
- require:
|
|
||||||
- pkg: postgresql-server
|
|
||||||
|
|
||||||
{%- endfor %}
|
|
||||||
|
|
||||||
|
# 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 %}
|
{%- endif %}
|
||||||
|
- onchanges:
|
||||||
|
- cmd: postgresql-start
|
||||||
|
|||||||
Reference in New Issue
Block a user