about summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-04-07 16:37:43 -0400
committerShea Levy <shea@shealevy.com>2014-04-07 16:37:43 -0400
commitefdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7 (patch)
treea135f7d1448d035bc149b2a995868fe67416edea /nixos/modules/services/databases
parentcea0460d41cd0719b0d82577f8fd6637415ff4ad (diff)
parente2066841106a6b89093ab685368742efa4e3c2c1 (diff)
downloadnixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar.gz
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar.bz2
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar.lz
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar.xz
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.tar.zst
nixlib-efdb8a10ed3c808ef32dda1f7bde894c3ef6a6e7.zip
Merge branch 'postgresql-user-fix' of git://github.com/ocharles/nixpkgs into fix-new-conduit
Create 'postgres' user and use pg_isready
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/postgresql.nix8
1 files changed, 7 insertions, 1 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix
index 33ee7244e3f4..ed66c15e304d 100644
--- a/nixos/modules/services/databases/postgresql.nix
+++ b/nixos/modules/services/databases/postgresql.nix
@@ -197,6 +197,7 @@ in
                 fi
                 rm -f ${cfg.dataDir}/*.conf
                 touch "${cfg.dataDir}/.first_startup"
+                touch "${cfg.dataDir}/postgresql-user-created"
             fi
 
             ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
@@ -225,11 +226,16 @@ in
         # Wait for PostgreSQL to be ready to accept connections.
         postStart =
           ''
-            while ! su -s ${pkgs.stdenv.shell} postgres -c 'psql postgres -c ""' 2> /dev/null; do
+            while ! ${pkgs.postgresql93}/bin/pg_isready > /dev/null; do
                 if ! kill -0 "$MAINPID"; then exit 1; fi
                 sleep 0.1
             done
 
+            if ! [ -e ${cfg.dataDir}/postgresql-user-created ]; then
+              createuser --superuser postgres
+              touch ${cfg.dataDir}/postgresql-user-created
+            fi
+
             if test -e "${cfg.dataDir}/.first_startup"; then
               ${optionalString (cfg.initialScript != null) ''
                 cat "${cfg.initialScript}" | su -s ${pkgs.stdenv.shell} postgres -c 'psql postgres'