Skip to content

Commit 783041b

Browse files
committed
Separate states for baking VM or container image
1 parent 186e972 commit 783041b

File tree

2 files changed

+59
-34
lines changed

2 files changed

+59
-34
lines changed

postgres/server/image.sls

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{%- from "postgres/map.jinja" import postgres with context -%}
2+
3+
# This state is used to launch PostgreSQL and enable it on "boot" with `pg_ctl`
4+
# during an image (Docker, Virtual Appliance, AMI) preparation
5+
6+
{%- if postgres.bake_image %}
7+
8+
include:
9+
- postgres.server
10+
11+
# An attempt to start PostgreSQL with `pg_ctl`
12+
13+
postgresql-start:
14+
cmd.run:
15+
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
16+
- runas: {{ postgres.user }}
17+
- unless:
18+
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
19+
- require:
20+
- file: postgresql-pg_hba
21+
22+
# Try to enable PostgreSQL in "manual" way
23+
24+
postgresql-enable:
25+
cmd.run:
26+
{%- if salt['file.file_exists']('/bin/systemctl') %}
27+
- name: systemctl enable {{ postgres.service }}
28+
{%- elif salt['cmd.which']('chkconfig') %}
29+
- name: chkconfig {{ postgres.service }} on
30+
{%- elif salt['file.file_exists']('/usr/sbin/update-rc.d') %}
31+
- name: update-rc.d {{ service }} defaults
32+
{%- else %}
33+
# Nothing to do
34+
- name: 'true'
35+
{%- endif %}
36+
- require:
37+
- cmd: postgresql-start
38+
39+
{%- else %}
40+
41+
postgresql-start:
42+
test.show_notification:
43+
- text: The 'postgres.bake_image' Pillar is disabled (set to 'False').
44+
45+
{%- endif %}

postgres/server.sls renamed to postgres/server/init.sls

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
{%- from "postgres/map.jinja" import postgres with context -%}
2-
3-
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra -%}
1+
{%- from "postgres/map.jinja" import postgres with context %}
42
3+
{%- set includes = [] %}
4+
{%- if postgres.bake_image %}
5+
{%- do includes.append('postgres.server.image') %}
6+
{%- endif %}
57
{%- if postgres.use_upstream_repo -%}
8+
{%- do includes.append('postgres.upstream') %}
9+
{%- endif %}
10+
11+
{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %}
12+
13+
{%- if includes -%}
614
715
include:
8-
- postgres.upstream
16+
{{ includes|yaml(false)|indent(2) }}
917
1018
{%- endif %}
1119
@@ -36,6 +44,8 @@ postgresql-server:
3644
- onlyif: test -f {{ path }}
3745
- require:
3846
- pkg: postgresql-server
47+
- require_in:
48+
- cmd: postgresql-cluster-prepared
3949
4050
{%- endfor %}
4151
@@ -120,34 +130,4 @@ postgresql-running:
120130
- watch:
121131
- file: postgresql-pg_hba
122132
123-
{%- else %}
124-
125-
# An attempt to launch PostgreSQL with `pg_ctl` during an image preparation
126-
127-
postgresql-start:
128-
cmd.run:
129-
- name: pg_ctl -D {{ postgres.conf_dir }} -l logfile start
130-
- runas: {{ postgres.user }}
131-
- unless:
132-
- ps -p $(head -n 1 {{ postgres.conf_dir }}/postmaster.pid) 2>/dev/null
133-
- require:
134-
- file: postgresql-pg_hba
135-
136-
# Try to enable PostgreSQL in "manual" way when baking an image
137-
138-
postgresql-enable:
139-
cmd.run:
140-
{%- if salt['file.file_exists']('/bin/systemctl') %}
141-
- name: systemctl enable {{ postgres.service }}
142-
{%- elif salt['cmd.which']('chkconfig') %}
143-
- name: chkconfig {{ postgres.service }} on
144-
{%- elif salt['file.file_exists']('/usr/sbin/update-rc.d') %}
145-
- name: update-rc.d {{ service }} defaults
146-
{%- else %}
147-
# Nothing to do
148-
- name: 'true'
149-
{%- endif %}
150-
- require:
151-
- cmd: postgresql-start
152-
153133
{%- endif %}

0 commit comments

Comments
 (0)