mirror of
https://github.com/saltstack-formulas/postgres-formula.git
synced 2025-04-16 09:40:26 +00:00
Separate states for baking VM or container image
This commit is contained in:
parent
186e972075
commit
783041b8cc
2 changed files with 59 additions and 34 deletions
45
postgres/server/image.sls
Normal file
45
postgres/server/image.sls
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{%- from "postgres/map.jinja" import postgres with context -%}
|
||||||
|
|
||||||
|
# This state is used to launch PostgreSQL and enable it on "boot" with `pg_ctl`
|
||||||
|
# during an image (Docker, Virtual Appliance, AMI) preparation
|
||||||
|
|
||||||
|
{%- if postgres.bake_image %}
|
||||||
|
|
||||||
|
include:
|
||||||
|
- postgres.server
|
||||||
|
|
||||||
|
# An attempt to start PostgreSQL with `pg_ctl`
|
||||||
|
|
||||||
|
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
|
||||||
|
- require:
|
||||||
|
- file: postgresql-pg_hba
|
||||||
|
|
||||||
|
# Try to enable PostgreSQL in "manual" way
|
||||||
|
|
||||||
|
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
|
||||||
|
{%- elif salt['file.file_exists']('/usr/sbin/update-rc.d') %}
|
||||||
|
- name: update-rc.d {{ service }} defaults
|
||||||
|
{%- else %}
|
||||||
|
# Nothing to do
|
||||||
|
- name: 'true'
|
||||||
|
{%- endif %}
|
||||||
|
- require:
|
||||||
|
- cmd: postgresql-start
|
||||||
|
|
||||||
|
{%- else %}
|
||||||
|
|
||||||
|
postgresql-start:
|
||||||
|
test.show_notification:
|
||||||
|
- text: The 'postgres.bake_image' Pillar is disabled (set to 'False').
|
||||||
|
|
||||||
|
{%- endif %}
|
|
@ -1,11 +1,19 @@
|
||||||
{%- from "postgres/map.jinja" import postgres with context -%}
|
{%- from "postgres/map.jinja" import postgres with context %}
|
||||||
|
|
||||||
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra -%}
|
|
||||||
|
|
||||||
|
{%- set includes = [] %}
|
||||||
|
{%- if postgres.bake_image %}
|
||||||
|
{%- do includes.append('postgres.server.image') %}
|
||||||
|
{%- endif %}
|
||||||
{%- if postgres.use_upstream_repo -%}
|
{%- if postgres.use_upstream_repo -%}
|
||||||
|
{%- do includes.append('postgres.upstream') %}
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %}
|
||||||
|
|
||||||
|
{%- if includes -%}
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- postgres.upstream
|
{{ includes|yaml(false)|indent(2) }}
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
@ -36,6 +44,8 @@ postgresql-server:
|
||||||
- onlyif: test -f {{ path }}
|
- onlyif: test -f {{ path }}
|
||||||
- require:
|
- require:
|
||||||
- pkg: postgresql-server
|
- pkg: postgresql-server
|
||||||
|
- require_in:
|
||||||
|
- cmd: postgresql-cluster-prepared
|
||||||
|
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
@ -120,34 +130,4 @@ postgresql-running:
|
||||||
- watch:
|
- watch:
|
||||||
- file: postgresql-pg_hba
|
- file: postgresql-pg_hba
|
||||||
|
|
||||||
{%- else %}
|
|
||||||
|
|
||||||
# An attempt to launch PostgreSQL with `pg_ctl` during an image preparation
|
|
||||||
|
|
||||||
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
|
|
||||||
- require:
|
|
||||||
- file: postgresql-pg_hba
|
|
||||||
|
|
||||||
# Try to enable PostgreSQL in "manual" way when baking an image
|
|
||||||
|
|
||||||
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
|
|
||||||
{%- elif salt['file.file_exists']('/usr/sbin/update-rc.d') %}
|
|
||||||
- name: update-rc.d {{ service }} defaults
|
|
||||||
{%- else %}
|
|
||||||
# Nothing to do
|
|
||||||
- name: 'true'
|
|
||||||
{%- endif %}
|
|
||||||
- require:
|
|
||||||
- cmd: postgresql-start
|
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
Loading…
Add table
Reference in a new issue