Commit 41baf77b authored by peter's avatar peter

Parametrise postgres versions

parent ba29601d
[Unit]
Description=PostgreSQL 9.5 database server
After=syslog.target
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGDATA={{pg_data}}/data/
OOMScoreAdjust=-1000
ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-9.5/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/pgsql-9.5/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-9.5/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
[Unit]
Description=PostgreSQL 9.4 database server
Description=PostgreSQL {{pg_version}} database server
After=syslog.target
After=network.target
[Service]
......@@ -8,10 +8,10 @@ User=postgres
Group=postgres
Environment=PGDATA={{pg_data}}/data/
OOMScoreAdjust=-1000
ExecStartPre=/usr/pgsql-9.4/bin/postgresql94-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-9.4/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/pgsql-9.4/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-9.4/bin/pg_ctl reload -D ${PGDATA} -s
ExecStartPre=/usr/pgsql-{{pg_version}}/bin/postgresql{{pg_trunc}}-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-{{pg_version}}/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/pgsql-{{pg_version}}/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/pgsql-{{pg_version}}/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
{% set postgres = salt['grains.filter_by']({
'Debian': {'pkg': 'postgresql', 'srv': 'postgresql'},
'RedHat': {'pkg': 'postgresql95-server', 'srv': 'postgresql-9.5' },
}, default='Debian') %}
{% if salt['grains.get']('os_family') == "RedHat" %}
{% set pg_version = salt['pillar.get']('pg_version', '9.5')|string %}
{% set pg_trunc = pg_version|string|replace(".", "") %}
{% set pg_data = salt['pillar.get']('pg_data', '/var/lib/pgsql/' + pg_version) %}
postgres:
pkg.installed:
- name: {{ postgres.pkg }}
- name: postgresql{{pg_trunc}}-server
service.running:
- enable: True
- name: {{ postgres.srv }}
{% set pg_data = salt['pillar.get']('pg_data', '/var/lib/pgsql/9.5') %}
- name: postgresql-{{pg_version}}
{% set confdir = pg_data + '/data' %}
......@@ -25,35 +22,37 @@ postgres:
- group
- makedirs: True
pgdg95:
pgdgi{{pg_trunc}}:
pkgrepo.managed:
- humanname: PostgreSQL 9.5 $releasever - $basearch
- baseurl: http://yum.postgresql.org/9.5/redhat/rhel-$releasever-$basearch
- humanname: PostgreSQL {{pg_version}} $releasever - $basearch
- baseurl: http://yum.postgresql.org/{{pg_version}}/redhat/rhel-$releasever-$basearch
- gpgcheck: 1
- gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-95
- gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-{{pg_trunc}}
- require:
- file: pgdg95_gpg
- file: pgdg{{pg_trunc}}_gpg
- require_in:
- pkg: postgres
pgdg95_gpg:
pgdg{{pg_trunc}}_gpg:
file.managed:
- name: /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-95
- name: /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-{{pg_trunc}}
- source: salt://postgres/files/rpm_gpg
systemd_file:
file.managed:
- name: /etc/systemd/system/postgresql-9.5.service
- source: salt://postgres/files/postgresql-9.5.service
- name: /etc/systemd/system/postgresql-{{pg_version}}.service
- source: salt://postgres/files/postgresql.service
- template: jinja
- context:
pg_data: {{pg_data}}
pg_version: {{pg_version}}
pg_trunc: {{pg_trunc}}
postgresql-initdb:
cmd.run:
- cwd: /
- user: root
- name: /usr/pgsql-9.5/bin/postgresql95-setup initdb
- name: /usr/pgsql-{{pg_version}}/bin/postgresql{{pg_trunc}}-setup initdb
- unless: test -f {{pg_data}}/data/postgresql.conf
- require_in:
- service: postgres
......@@ -65,18 +64,16 @@ postgresql-initdb:
- file: {{pg_data}}
{% else %}
{% set pg_version = salt['pillar.get']('pg_version', '9.3') %}
{% set pg_version = salt['pillar.get']('pg_version', '9.5') %}
{% set confdir = '/etc/postgresql/' ~ pg_version ~ '/main' %}
postgres:
pkg.installed:
- name: {{ postgres.pkg }}-{{pg_version}}
- name: postgresql-{{pg_version}}
service.running:
- enable: True
- name: {{ postgres.srv }}
- name: postgresql
{% if pg_version != '9.3' %}
pg_repo:
pkgrepo.managed:
- name: deb http://apt.postgresql.org/pub/repos/apt/ {{grains['oscodename']}}-pgdg main
......@@ -85,7 +82,6 @@ pg_repo:
- key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
- require_in:
- pkg: postgres
{% endif %}
{% endif %}
......@@ -99,6 +95,14 @@ pg_repo:
- service: postgres
- mode: 600
update_max_connections:
file.replace:
- name : {{confdir}}/postgresql.conf
- pattern: max_connections = 100
- repl: max_connections = 500
- watch_in:
- service: postgres
{% if pillar['pg_hosts'] is defined %}
{{confdir}}/postgresql.conf:
file.append:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment