@@ -20,6 +20,27 @@ postgresql-server:
2020 - pkgrepo: postgresql- repo
2121{%- endif % }
2222
23+ {%- if ' bin_dir' in postgres % }
24+
25+ # Make server binaries available in $PATH
26+
27+ {%- for bin in postgres.server_bins % }
28+
29+ {%- set path = salt[' file.join' ](postgres.bin_dir, bin ) % }
30+
31+ {{ bin }}:
32+ alternatives.install:
33+ - link: {{ salt[' file.join' ](' /usr/bin' , bin ) }}
34+ - path: {{ path }}
35+ - priority: 30
36+ - onlyif: test - f {{ path }}
37+ - require:
38+ - pkg: postgresql- server
39+
40+ {%- endfor % }
41+
42+ {%- endif % }
43+
2344postgresql- cluster- prepared:
2445 cmd.run:
2546 - name: {{ postgres.prepare_cluster.command }}
@@ -93,23 +114,28 @@ postgresql-tablespace-dir-{{ name }}:
93114
94115{%- endfor % }
95116
96- {%- if ' bin_dir' in postgres % }
97-
98- # Make server binaries available in $PATH
99-
100- {%- for bin in postgres.server_bins % }
101-
102- {%- set path = salt[' file.join' ](postgres.bin_dir, bin ) % }
103-
104- {{ bin }}:
105- alternatives.install:
106- - link: {{ salt[' file.join' ](' /usr/bin' , bin ) }}
107- - path: {{ path }}
108- - priority: 30
109- - onlyif: test - f {{ path }}
110- - require:
111- - pkg: postgresql- server
112-
113- {%- endfor % }
117+ # An attempt to launch PostgreSQL with `pg_ctl` if service failed to start
118+ # with init system or Salt unable to load the `service` state module
119+ postgresql- start:
120+ cmd.run:
121+ - name: pg_ctl - D {{ postgres.conf_dir }} - l logfile start
122+ - runas: {{ postgres.user }}
123+ - unless:
124+ - ps - p $ (head - n 1 {{ postgres.conf_dir }}/ postmaster.pid) 2 > / dev/ null
125+ - onfail:
126+ - service: postgresql- running
114127
128+ # Try to enable PostgreSQL in "manual" way for systemd and RedHat-based distros.
129+ # The packages for other OS (i.e. `*.deb`) should do it automatically by default
130+ postgresql- enable:
131+ cmd.run:
132+ {%- if salt[' file.file_exists' ](' /bin/systemctl' ) % }
133+ - name: systemctl enable {{ postgres.service }}
134+ {%- elif salt[' cmd.which' ](' chkconfig' ) % }
135+ - name: chkconfig {{ postgres.service }} on
136+ {%- else % }
137+ # Nothing to do
138+ - name: ' true'
115139{%- endif % }
140+ - onchanges:
141+ - cmd: postgresql- start
0 commit comments