[cubicweb/postgresql] patch postgresql init for wheezy, use now available postgres_extension state
authorArthur Lutz <arthur.lutz@logilab.fr>
Thu, 09 Apr 2015 10:57:28 +0200
changeset 31 f870744fcff8
parent 30 415eeb466fc6
child 32 6b02c03c9e29
[cubicweb/postgresql] patch postgresql init for wheezy, use now available postgres_extension state
cubicweb/postgres.sls
cubicweb/postgresql_patched_init
--- a/cubicweb/postgres.sls	Mon Jun 15 10:23:08 2015 +0200
+++ b/cubicweb/postgres.sls	Thu Apr 09 10:57:28 2015 +0200
@@ -3,47 +3,50 @@
     - pkgs:
       - postgresql-9.1
       - postgresql-contrib-9.1
-      - postgresql-plpython-9.1
+  {% if grains['oscodename'] == 'wheezy' %}
+  file.managed:
+    - name: /etc/init.d/postgresql
+    - source: salt://cubicweb/postgresql_patched_init
+    - require_in:
+      - service: postgresql
+  {% endif %}
   service.running:
     - name: postgresql
 
+postgresql-plpython-9.1:
+  pkg.installed
+
 /etc/postgresql/9.1/main/pg_hba.conf:
   file.append:
     - text:
           - host    all             all             0.0.0.0/0            md5
-    - watch_in : pgserver
+    - watch_in : 
+      service: postgresql
 
 {% for vhostname, vhost in pillar['cubicweb_apps'].iteritems() %}
  {% for name, config in vhost.iteritems() %}
 
 pg-{{vhostname}}-{{name}}:
-  postgres_database:
-    - present
+  postgres_user.present:
+    - name: {{ config.get('database',{}).get('user','cubicweb') }}
+    - password: {{ config.get('database',{}).get('password', 'cub1cweb') }}
+    - user: postgres
+    - require:
+      - service: postgresql
+  postgres_database.present:
     - name: {{ config.database.name }}
     - owner: {{ config.database.user }}
     - encoding: 'UTF8'
     - template: template0
     - require:
       - postgres_user: pg-{{vhostname}}-{{name}}
-      - service: pg-server
-  postgres_user:
-    - present
-    - name: {{ config.database.user }}
-    - password: {{ config.database.password }}
+      - service: postgresql
+  postgres_extension.present:
+    - name: plpythonu
     - require:
-      - service: pg-server
-  module.run:
-    - name: postgres.create_extension
-    - m_name: plpythonu
-    - require:
-      - service: pg-server
-
-# Not yet available
-#  postgres_extension.present:
-#    - name: plpythonu
-#    - require:
-#      - service: pg-server
-#      - postgres_database: pg-{{vhostname}}-{{name}}
+      - service: postgresql
+      - pkg: postgresql-plpython-9.1
+      - postgres_database: pg-{{vhostname}}-{{name}}
  {% endfor %}
 {% endfor %}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/postgresql_patched_init	Thu Apr 09 10:57:28 2015 +0200
@@ -0,0 +1,55 @@
+#!/bin/sh
+set -e
+
+### BEGIN INIT INFO
+# Provides:             postgresql
+# Required-Start:       $local_fs $remote_fs $network $time
+# Required-Stop:        $local_fs $remote_fs $network $time
+# Should-Start:         $syslog
+# Should-Stop:          $syslog
+# Default-Start:        2 3 4 5
+# Default-Stop:         0 1 6
+# Short-Description:    PostgreSQL RDBMS server
+### END INIT INFO
+
+# Setting environment variables for the postmaster here does not work; please
+# set them in /etc/postgresql/<version>/<cluster>/environment instead.
+
+[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0
+
+. /usr/share/postgresql-common/init.d-functions
+
+# versions can be specified explicitly
+if [ -n "$2" ]; then
+    versions="$2 $3 $4 $5 $6 $7 $8 $9"
+else
+    get_versions
+fi
+
+case "$1" in
+    start|stop|restart|reload)
+        for v in $versions; do
+            $1 $v
+        done
+        ;;
+    status)
+	# PATCH BEGIN
+        LS=`pg_lsclusters -h`
+        # no clusters -> unknown status
+        [ -n "$LS" ] || exit 4
+        echo "$LS" | awk 'BEGIN {rc=0} {if (match($4, "down")) rc=3; printf ("%s/%s (port %s): %s\n", $1, $2, $3, $4)}; END {exit rc}'
+	# PATCH END
+        ;;
+    force-reload)
+        for v in $versions; do
+            reload $v
+        done
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"
+        exit 1
+        ;;
+esac
+
+exit 0
+