postgresql.nix: Use User/Group instead of su
This commit is contained in:
parent
13d747c11a
commit
5cf702e1c1
@ -22,8 +22,6 @@ let
|
|||||||
|
|
||||||
postgresql = postgresqlAndPlugins cfg.package;
|
postgresql = postgresqlAndPlugins cfg.package;
|
||||||
|
|
||||||
run = "su -s ${pkgs.stdenv.shell} postgres";
|
|
||||||
|
|
||||||
flags = optional cfg.enableTCPIP "-i";
|
flags = optional cfg.enableTCPIP "-i";
|
||||||
|
|
||||||
# The main PostgreSQL configuration file.
|
# The main PostgreSQL configuration file.
|
||||||
@ -157,7 +155,7 @@ in
|
|||||||
|
|
||||||
environment.systemPackages = [postgresql];
|
environment.systemPackages = [postgresql];
|
||||||
|
|
||||||
jobs.postgresql =
|
boot.systemd.services.postgresql =
|
||||||
{ description = "PostgreSQL server";
|
{ description = "PostgreSQL server";
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
@ -176,14 +174,27 @@ in
|
|||||||
if ! test -e ${cfg.dataDir}; then
|
if ! test -e ${cfg.dataDir}; then
|
||||||
mkdir -m 0700 -p ${cfg.dataDir}
|
mkdir -m 0700 -p ${cfg.dataDir}
|
||||||
chown -R postgres ${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
|
rm -f ${cfg.dataDir}/*.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf
|
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.
|
# Wait for PostgreSQL to be ready to accept connections.
|
||||||
postStart =
|
postStart =
|
||||||
@ -192,16 +203,6 @@ in
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user