Skip to content

Add basic postgres.server.remove state #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
70cff03
Darwin support
Sep 23, 2017
05b8d23
Darwin support
Sep 23, 2017
5aa0d3c
Darwin support
Sep 23, 2017
26a093d
Darwin support
Sep 23, 2017
341cfc6
Darwin support
Sep 23, 2017
574ce7d
Merge pull request #1 from saltstack-formulas/master
noelmcloughlin Jan 17, 2018
421f2f5
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Feb 9, 2018
ab0da7e
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Mar 8, 2018
3086b95
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Mar 17, 2018
66486b9
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Mar 19, 2018
758d9bb
Darwin support
Sep 23, 2017
6d5a436
Darwin support
Sep 23, 2017
d8d0f02
Darwin support
Sep 23, 2017
c9ee472
Darwin support
Sep 23, 2017
fb8e1ba
Darwin support
Sep 23, 2017
211f1a8
'env' should be [] not {} in defaults.yml
noelmcloughlin Jan 22, 2018
00fa472
Tidyup alternatives system priority hardcoding
noelmcloughlin Jan 14, 2018
d58478b
Support for upstream postgresql.org zypp repo after PR review
noelmcloughlin Jan 14, 2018
886f666
Do not fail states during mock test mode
vutny Feb 22, 2018
c41d324
POSTGRESAPP on MacOS
noelmcloughlin Mar 8, 2018
c6e4f19
Homebrew Postgres on MacOS
noelmcloughlin Mar 8, 2018
63b9ae0
Add support for configure pg_ident.conf
EvaSDK Jan 16, 2018
1d719a3
Add example usage of identity mapping
EvaSDK Mar 12, 2018
9156437
Fix suse alternatives #189
noelmcloughlin Mar 17, 2018
76ee36b
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Mar 20, 2018
354e202
corrections for packages
noelmcloughlin Mar 20, 2018
c1aa119
Merge branch 'master' into pkgs
noelmcloughlin Mar 20, 2018
2809d30
Merge branch 'master' of https://github.com/noelmcloughlin/postgres-f…
noelmcloughlin Mar 20, 2018
f2f7c81
Merge branch 'pkgs' of https://github.com/noelmcloughlin/postgres-for…
noelmcloughlin Mar 20, 2018
5edd2ac
Merge branch 'master' of https://github.com/saltstack-formulas/postgr…
noelmcloughlin Mar 22, 2018
c9659d9
Basic RemoveState
noelmcloughlin Mar 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions postgres/client.sls → postgres/client/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ include:
postgresql-client-libs:
pkg.installed:
- pkgs: {{ pkgs }}
{%- if postgres.use_upstream_repo == true %}
{%- if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{%- endif %}
{%- if postgres.use_upstream_repo == true %}
- refresh: True
- require:
- pkgrepo: postgresql-repo
{%- endif %}
{%- endif %}

# Alternatives system. Make client binaries available in $PATH
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- for bin in postgres.client_bins %}
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}

{{ bin }}:
postgresql-{{ bin }}-altinstall:
alternatives.install:
- name: {{ bin }}
- link: {{ salt['file.join']('/usr/bin', bin) }}
- path: {{ path }}
- priority: {{ postgres.linux.altpriority }}
Expand All @@ -37,4 +41,4 @@ postgresql-client-libs:
- pkg: postgresql-client-libs

{%- endfor %}
{%- endif %}
{%- endif %}
30 changes: 30 additions & 0 deletions postgres/client/remove.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{%- from "postgres/map.jinja" import postgres with context -%}

# Remove Postgres client and dev packages
postgresql-client-dev-removed:
pkg.purged:
- pkgs:
{% if postgres.pkg_client %}
- {{ postgres.pkg_client }}
{% endif %}
{% if postgres.pkg_dev %}
- {{ postgres.pkg_dev }}
{% endif %}
{% if postgres.pkg_libpq_dev %}
- {{ postgres.pkg_libpq_dev }}
{% endif %}
{% if postgres.pkg_python %}
- {{ postgres.pkg_python }}
{% endif %}
{# these packages probably should go too #}
- postgresql-common
- postgresql-client-common
- libpostgresql-jdbc-java
{%- for version in ['', '92', '93', '94', '95', '96', '10',] %}
- postgresql{{ version }}
{%- endfor %}

postgresql-etc-removed:
file.absent:
- names:
- /etc/postgresql
3 changes: 3 additions & 0 deletions postgres/codenamemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@

## Fedora
# `oscodename` grain has long distro name
{{ fedora_codename('Fedora-28', '10.3', 'Fedora 28 (Twenty Eight)') }}
{{ fedora_codename('Fedora-27', '9.6', 'Fedora 27 (Twenty Seven)') }}
{{ fedora_codename('Fedora-26', '9.6', 'Fedora 26 (Twenty Six)') }}
{{ fedora_codename('Fedora-25', '9.5', 'Fedora 25 (Twenty Five)') }}
{{ fedora_codename('Fedora-24', '9.5', 'Fedora 24 (Twenty Four)') }}
{{ fedora_codename('Fedora-23', '9.4', 'Fedora 23 (Twenty Three)') }}
Expand Down
5 changes: 1 addition & 4 deletions postgres/dev.sls
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ install-postgres-libpq-dev:
- name: {{ postgres.pkg_libpq_dev }}
{% endif %}

{% endif %}


{% if grains.os == 'MacOS' %}
{% elif grains.os == 'MacOS' %}

# Darwin maxfiles limits
{% if postgres.limits.soft or postgres.limits.hard %}
Expand Down
32 changes: 2 additions & 30 deletions postgres/dropped.sls
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
{% from "postgres/map.jinja" import postgres with context %}

postgresql-dead:
service.dead:
- name: {{ postgres.service }}

postgresql-removed:
pkg.removed:
- pkgs:
{% if postgres.pkg %}
- {{ postgres.pkg }}
{% endif %}
{% if postgres.pkg_client %}
- {{ postgres.pkg_client }}
{% endif %}
{% if postgres.pkg_dev %}
- {{ postgres.pkg_dev }}
{% endif %}
{% if postgres.pkg_libpq_dev %}
- {{ postgres.pkg_libpq_dev }}
{% endif %}
{% if postgres.pkgs_extra %}
{% for pkg in postgres.pkgs_extra %}
- {{ pkg }}
{% endfor %}
{% endif %}

postgres-dir-absent:
file.absent:
- name: {{ postgres.conf_dir }}
include:
- postgresql.server.remove
14 changes: 13 additions & 1 deletion postgres/osmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Debian:
file: /etc/apt/sources.list.d/pgdg.list
pkg_repo_keyid: ACCC4CF8
pkg_dev: postgresql-server-dev-all
pkg_libpq_dev: libpq-dev

FreeBSD:
user: pgsql
Expand Down Expand Up @@ -52,6 +53,8 @@ RedHat:

# directory containing PostgreSQL client executables
bin_dir: /usr/pgsql-{{ repo.version }}/bin
dev_bins:
- ecg
client_bins:
- clusterdb
- createdb
Expand All @@ -66,17 +69,20 @@ RedHat:
- pg_dump
- pg_dumpall
- pg_isready
- pg_receivewal
- pg_receivexlog
- pg_restore
- pg_rewind
- pg_test_fsync
- pg_test_timing
- pg_upgrade
- pg_waldump
- pg_xlogdump
- pgbench
- psql
- reindexdb
- vacuumdb

server_bins:
- initdb
- pg_controldata
Expand Down Expand Up @@ -122,20 +128,26 @@ Suse:
# Alternatives system
linux:
altpriority: 30

# directory containing PostgreSQL client executables
bin_dir: /usr/pgsql-{{ repo.version }}/bin
dev_bins:
- ecg
client_bins:
- pg_archivecleanup
- pg_config
- pg_isready
- pg_receivewal
- pg_receivexlog
- pg_rewind
- pg_test_fsync
- pg_test_timing
- pg_upgrade
- pg_waldump
- pg_xlogdump
- pgbench
- psql
- reindexdb
- vacuumdb
server_bins:
- initdb
- pg_controldata
Expand Down
15 changes: 11 additions & 4 deletions postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ include:
{%- endif %}

{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %}

# Install, configure and start PostgreSQL server

postgresql-server:
pkg.installed:
- pkgs: {{ pkgs }}
{%- if postgres.use_upstream_repo == true %}
{%- if postgres.fromrepo %}
- fromrepo: {{ postgres.fromrepo }}
{%- endif %}
{%- if postgres.use_upstream_repo == true %}
- refresh: True
- require:
- pkgrepo: postgresql-repo
{%- endif %}
{%- endif %}
{%- if grains.os == 'MacOS' %}
#Register as Launchd LaunchAgent for system users
- require_in:
Expand All @@ -33,15 +38,17 @@ postgresql-server:
- group: wheel
- require_in:
- service: postgresql-running

{%- else %}

# Alternatives system. Make server binaries available in $PATH
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- for bin in postgres.server_bins %}
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}

{{ bin }}:
postgresql-{{ bin }}-altinstall:
alternatives.install:
- name: {{ bin }}
- link: {{ salt['file.join']('/usr/bin', bin) }}
- path: {{ path }}
- priority: {{ postgres.linux.altpriority }}
Expand All @@ -54,7 +61,7 @@ postgresql-server:
{%- endfor %}
{%- endif %}

{%- endif %}
{%- endif %}

postgresql-cluster-prepared:
cmd.run:
Expand Down
96 changes: 96 additions & 0 deletions postgres/server/remove.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{%- from "postgres/map.jinja" import postgres with context %}

{%- if 'pkg_repo' in postgres -%}
{%- if postgres.use_upstream_repo -%}
{## Remove the repo ##}
postgresql-repo-removed:
pkgrepo.absent:
- name: {{ postgres.pkg_repo.name }}
{%- if 'pkg_repo_keyid' in postgres %}
- keyid: {{ postgres.pkg_repo_keyid }}
{%- endif %}
- require_in:
- pkg: postgresql-server-removed
{%- endif -%}
{%- endif -%}

{%- if not postgres.bake_image %}
# Stop PostgreSQL service with OS init
postgresql-dead:
service.dead:
- name: {{ postgres.service }}
- enable: False
{%- endif %}

# Remove PostgreSQL server packages
postgresql-server-removed:
pkg.purged:
- pkgs:
{% if postgres.pkg %}
- {{ postgres.pkg }}
{% endif %}
{% if postgres.pkg_client %}
- {{ postgres.pkg_client }}
{% endif %}
{% if postgres.pkg_dev %}
- {{ postgres.pkg_dev }}
{% endif %}
{% if postgres.pkg_libpq_dev %}
- {{ postgres.pkg_libpq_dev }}
{% endif %}
{% if postgres.pkgs_extra %}
{% for pkg in postgres.pkgs_extra %}
- {{ pkg }}
{% endfor %}
{% endif %}
{% if postgres.pkg_libs %}
- {{ postgres.pkg_libs }}
{% endif %}
{# sometimes postgres-init remains. Maybe systemd.service related? #}
- postgres-init
- postgres-contrib
{# postgres-common remains on Ubuntu #}
- postgresql-common
- postgresql-jdbc
{# upstream package repos #}
{%- for version in ['', '92', '93', '94', '95', '96', '10',] %}
- postgresql{{ version }}-server
- postgresql{{ version }}-server
- postgresql{{ version }}
- postgresql{{ version }}-libs
- postgresql{{ version }}-contrib
{%- endfor %}

{%- if 'bin_dir' in postgres %}
{%- for bin in postgres.server_bins %}
{%- for version in ['9.2', '9.3', '9.4', '9.5', '9.6', '10',] %}
{%- set path = salt['file.join']('/usr/pgsql-{{ version }}/bin/', bin) %}

postgresql{{ version }}-{{ bin }}-altremove:
alternatives.remove:
- name: postgresql-{{ bin }}
- path: {{ path }}
- require:
- pkg: postgresql-server-removed
- onlyif: test -f {{ path }}

{%- endfor %}
{%- endfor %}
{%- endif %}

postgresql-dataconf-removed:
file.absent:
- names:
- {{ postgres.conf_dir }}
- {{ postgres.data_dir }}
- /var/lib/postgresql
- /var/lib/pgsql

{%- for name, tblspace in postgres.tablespaces|dictsort() %}
postgresql-tablespace-dir-{{ name }}-removed:
file.absent:
- name: {{ tblspace.directory }}
- require:
- file: postgresql-dataconf-removed
{% endfor %}

5 changes: 1 addition & 4 deletions postgres/upstream.sls
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ postgresql-repo:

{%- endif -%}

{%- else -%}
{%- elif grains.os not in ('Windows', 'MacOS',) %}

# Notify that we don't manage this distro
{% if grains.os not in ('Windows', 'MacOS',) %}
postgresql-repo:
test.show_notification:
- text: |
PostgreSQL does not provide package repository for {{ grains['osfinger'] }}
{% endif %}

{%- endif %}