diff --git a/postgres/server/image.sls b/postgres/server/image.sls new file mode 100644 index 0000000..1cd3d5b --- /dev/null +++ b/postgres/server/image.sls @@ -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 %} diff --git a/postgres/server.sls b/postgres/server/init.sls similarity index 72% rename from postgres/server.sls rename to postgres/server/init.sls index 8c12ba4..181840b 100644 --- a/postgres/server.sls +++ b/postgres/server/init.sls @@ -1,11 +1,19 @@ -{%- from "postgres/map.jinja" import postgres with context -%} - -{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra -%} +{%- from "postgres/map.jinja" import postgres with context %} +{%- set includes = [] %} +{%- if postgres.bake_image %} + {%- do includes.append('postgres.server.image') %} +{%- endif %} {%- if postgres.use_upstream_repo -%} + {%- do includes.append('postgres.upstream') %} +{%- endif %} + +{%- set pkgs = [postgres.pkg] + postgres.pkgs_extra %} + +{%- if includes -%} include: - - postgres.upstream + {{ includes|yaml(false)|indent(2) }} {%- endif %} @@ -36,6 +44,8 @@ postgresql-server: - onlyif: test -f {{ path }} - require: - pkg: postgresql-server + - require_in: + - cmd: postgresql-cluster-prepared {%- endfor %} @@ -120,34 +130,4 @@ postgresql-running: - watch: - 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 %}