diff options
author | Nikolay Amiantov <ab@fmap.me> | 2016-02-09 03:07:23 +0300 |
---|---|---|
committer | Nikolay Amiantov <ab@fmap.me> | 2016-02-10 02:12:05 +0300 |
commit | 90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4 (patch) | |
tree | c0184aa32349efc3e688cc21056b7e35e34352dd /nixos | |
parent | 0024c10a5c974ee41c7bc69cd61faaa920f3a9d4 (diff) | |
download | nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar.gz nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar.bz2 nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar.lz nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar.xz nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.tar.zst nixpkgs-90ef11ddcdb8ba0c1bddcd50f1a88df3c42f5cf4.zip |
postgresql service: don't use su
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/databases/postgresql.nix | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index c2045a5859c..957fb4723a5 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -177,7 +177,7 @@ in users.extraGroups.postgres.gid = config.ids.gids.postgres; - environment.systemPackages = [postgresql]; + environment.systemPackages = [ postgresql ]; systemd.services.postgresql = { description = "PostgreSQL Server"; @@ -187,35 +187,37 @@ in environment.PGDATA = cfg.dataDir; - path = [ pkgs.su postgresql ]; + path = [ postgresql ]; preStart = '' - # Initialise the database. + # Create data directory. if ! test -e ${cfg.dataDir}/PG_VERSION; then - mkdir -m 0700 -p ${cfg.dataDir} - rm -f ${cfg.dataDir}/*.conf - if [ "$(id -u)" = 0 ]; then - chown -R postgres ${cfg.dataDir} - su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root' - else - # For non-root operation. - initdb - fi - # See postStart! - touch "${cfg.dataDir}/.first_startup" + mkdir -m 0700 -p ${cfg.dataDir} + rm -f ${cfg.dataDir}/*.conf + chown -R postgres:postgres ${cfg.dataDir} fi + ''; # */ + script = + '' + # Initialise the database. + if ! test -e ${cfg.dataDir}/PG_VERSION; then + initdb -U root + # See postStart! + touch "${cfg.dataDir}/.first_startup" + fi ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf" ${optionalString (cfg.recoveryConfig != null) '' ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \ "${cfg.dataDir}/recovery.conf" ''} - ''; # */ + + exec postgres ${toString flags} + ''; serviceConfig = - { ExecStart = "@${postgresql}/bin/postgres postgres ${toString flags}"; - ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + { ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; User = "postgres"; Group = "postgres"; PermissionsStartOnly = true; |