Author: eelco
Date: Mon Mar 19 16:49:13 2012
New Revision: 33262
URL: https://nixos.org/websvn/nix/?rev=33262&sc=1

Log:
* Improve the Postgres Upstart job: don't use pg_ctl, let Upstart
  monitor the postgres process directly (so that it can be restarted
  if necessary), let Upstart send SIGTERM to postgres to shut it down
  gracefully.  Also drop the Mediawiki references.

Modified:
   nixos/trunk/modules/services/databases/postgresql.nix

Modified: nixos/trunk/modules/services/databases/postgresql.nix
==============================================================================
--- nixos/trunk/modules/services/databases/postgresql.nix       Mon Mar 19 
16:05:29 2012        (r33261)
+++ nixos/trunk/modules/services/databases/postgresql.nix       Mon Mar 19 
16:49:13 2012        (r33262)
@@ -22,7 +22,7 @@
 
   postgresql = postgresqlAndPlugins pkgs.postgresql;
 
-  run = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} postgres";
+  run = "su -s ${pkgs.stdenv.shell} postgres";
 
   flags = optional cfg.enableTCPIP "-i";
 
@@ -74,13 +74,7 @@
       };
 
       authentication = mkOption {
-        default = ''
-          # Generated file; do not edit!
-          local all mediawiki        ident mediawiki-users
-          local all all              ident sameuser
-          host  all all 127.0.0.1/32 md5
-          host  all all ::1/128      md5
-        '';
+        default = "";
         description = ''
           Defines how users authenticate themselves to the server.
         '';
@@ -136,6 +130,14 @@
 
   config = mkIf config.services.postgresql.enable {
 
+    services.postgresql.authentication =
+      ''
+        # Generated file; do not edit!
+        local all all              ident sameuser
+        host  all all 127.0.0.1/32 md5
+        host  all all ::1/128      md5
+      '';
+        
     users.extraUsers = singleton
       { name = "postgres";
         description = "PostgreSQL server user";
@@ -146,13 +148,6 @@
 
     environment.systemPackages = [postgresql];
 
-    # !!! This should be be in the mediawiki module, obviously.
-    services.postgresql.identMap =
-      ''
-        mediawiki-users root   mediawiki
-        mediawiki-users wwwrun mediawiki
-      '';
-
     jobs.postgresql =
       { description = "PostgreSQL server";
 
@@ -163,35 +158,37 @@
             PGDATA = cfg.dataDir;
           };
 
+        path = [ pkgs.su postgresql ];
+
         preStart =
           ''
             # Initialise the database.
             if ! test -e ${cfg.dataDir}; then
                 mkdir -m 0700 -p ${cfg.dataDir}
                 chown -R postgres ${cfg.dataDir}
-                ${run} -c '${postgresql}/bin/initdb -U root'
+                ${run} -c 'initdb -U root'
                 rm -f ${cfg.dataDir}/*.conf
             fi
 
             ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf
+          ''; # */
+
+        exec = "${run} -c 'postgres ${toString flags}'";
 
-            # We'd like to use the `-w' flag here to wait until the
-            # database is up, but it requires a `postgres' user to
-            # exist.  And we can't call `createuser' before the
-            # database is running.
-            ${run} -c '${postgresql}/bin/pg_ctl start -o "${toString flags}"'
-
-            # So wait until the server is up.  `pg_ctl status' doesn't
-            # work (apparently, it just checks whether the server is
-            # running), so try to connect with psql.
-            while ! ${postgresql}/bin/psql postgres -c ""; do
+        # Wait for PostgreSQL to be ready to accept connections.
+        postStart =
+          ''
+            while ! psql postgres -c ""; do
+                stop_check
                 sleep 1
             done
-          ''; # */
+          '';
 
-        postStop =
+        extraConfig =
           ''
-            ${run} -c '${postgresql}/bin/pg_ctl stop -m fast'
+            # Give Postgres a decent amount of time to clean up after
+            # receiving Upstart's SIGTERM.
+            kill timeout 60
           '';
       };
 
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to