From 5cf702e1c130483caa13e3bb34df0a715679fd14 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 1 Oct 2012 16:47:54 -0400 Subject: [PATCH] postgresql.nix: Use User/Group instead of su --- modules/services/databases/postgresql.nix | 31 ++++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/services/databases/postgresql.nix b/modules/services/databases/postgresql.nix index a52d241e96c..caf9a586eb1 100644 --- a/modules/services/databases/postgresql.nix +++ b/modules/services/databases/postgresql.nix @@ -22,8 +22,6 @@ let postgresql = postgresqlAndPlugins cfg.package; - run = "su -s ${pkgs.stdenv.shell} postgres"; - flags = optional cfg.enableTCPIP "-i"; # The main PostgreSQL configuration file. @@ -157,7 +155,7 @@ in environment.systemPackages = [postgresql]; - jobs.postgresql = + boot.systemd.services.postgresql = { description = "PostgreSQL server"; wantedBy = [ "multi-user.target" ]; @@ -176,14 +174,27 @@ in if ! test -e ${cfg.dataDir}; then mkdir -m 0700 -p ${cfg.dataDir} chown -R postgres ${cfg.dataDir} - ${run} -c 'initdb -U root' + su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root' rm -f ${cfg.dataDir}/*.conf fi ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf ''; # */ - exec = "${run} -c 'postgres ${toString flags}'"; + serviceConfig = + { ExecStart = "@${postgresql}/bin/postgres postgres ${toString flags}"; + User = "postgres"; + Group = "postgres"; + PermissionsStartOnly = true; + + # Shut down Postgres using SIGINT ("Fast Shutdown mode"). See + # http://www.postgresql.org/docs/current/static/server-shutdown.html + KillSignal = "SIGINT"; + + # Give Postgres a decent amount of time to clean up after + # receiving systemd's SIGINT. + TimeoutSec = 60; + }; # Wait for PostgreSQL to be ready to accept connections. postStart = @@ -192,16 +203,6 @@ in sleep 1 done ''; - - serviceConfig = - { # Shut down Postgres using SIGINT ("Fast Shutdown mode"). See - # http://www.postgresql.org/docs/current/static/server-shutdown.html - KillSignal = "SIGINT"; - - # Give Postgres a decent amount of time to clean up after - # receiving systemd's SIGINT. - TimeoutSec = 60; - }; }; };