nixos/postgresql: replace deprecated usage of PermissionsStartOnly
This commit is contained in:
parent
e50e89e1a8
commit
f42f8a6d3c
@ -292,34 +292,28 @@ in
|
|||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
|
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
||||||
# Cleanup the data directory.
|
# Cleanup the data directory.
|
||||||
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
|
||||||
rm -f ${cfg.dataDir}/*.conf
|
rm -f ${cfg.dataDir}/*.conf
|
||||||
fi
|
|
||||||
'';
|
|
||||||
|
|
||||||
script =
|
|
||||||
''
|
|
||||||
# Initialise the database.
|
# Initialise the database.
|
||||||
if ! test -e ${cfg.dataDir}/PG_VERSION; then
|
|
||||||
initdb -U ${cfg.superUser} ${concatStringsSep " " cfg.initdbArgs}
|
initdb -U ${cfg.superUser} ${concatStringsSep " " cfg.initdbArgs}
|
||||||
|
|
||||||
# See postStart!
|
# See postStart!
|
||||||
touch "${cfg.dataDir}/.first_startup"
|
touch "${cfg.dataDir}/.first_startup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
|
ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
|
||||||
${optionalString (cfg.recoveryConfig != null) ''
|
${optionalString (cfg.recoveryConfig != null) ''
|
||||||
ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \
|
ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \
|
||||||
"${cfg.dataDir}/recovery.conf"
|
"${cfg.dataDir}/recovery.conf"
|
||||||
''}
|
''}
|
||||||
|
|
||||||
exec postgres
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = mkMerge [
|
serviceConfig = mkMerge [
|
||||||
{ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
{ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
User = "postgres";
|
User = "postgres";
|
||||||
Group = "postgres";
|
Group = "postgres";
|
||||||
PermissionsStartOnly = true;
|
|
||||||
RuntimeDirectory = "postgresql";
|
RuntimeDirectory = "postgresql";
|
||||||
Type = if versionAtLeast cfg.package.version "9.6"
|
Type = if versionAtLeast cfg.package.version "9.6"
|
||||||
then "notify"
|
then "notify"
|
||||||
@ -333,16 +327,15 @@ in
|
|||||||
# Give Postgres a decent amount of time to clean up after
|
# Give Postgres a decent amount of time to clean up after
|
||||||
# receiving systemd's SIGINT.
|
# receiving systemd's SIGINT.
|
||||||
TimeoutSec = 120;
|
TimeoutSec = 120;
|
||||||
}
|
|
||||||
(mkIf (cfg.dataDir == "/var/lib/postgresql/${cfg.package.psqlSchema}") {
|
ExecStart = "${postgresql}/bin/postgres";
|
||||||
StateDirectory = "postgresql postgresql/${cfg.package.psqlSchema}";
|
|
||||||
StateDirectoryMode = if groupAccessAvailable then "0750" else "0700";
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
# Wait for PostgreSQL to be ready to accept connections.
|
# Wait for PostgreSQL to be ready to accept connections.
|
||||||
postStart =
|
ExecStartPost =
|
||||||
''
|
let
|
||||||
|
setupScript = pkgs.writeScript "postgresql-setup" ''
|
||||||
|
#!${pkgs.runtimeShell} -e
|
||||||
|
|
||||||
PSQL="${pkgs.utillinux}/bin/runuser -u ${cfg.superUser} -- psql --port=${toString cfg.port}"
|
PSQL="${pkgs.utillinux}/bin/runuser -u ${cfg.superUser} -- psql --port=${toString cfg.port}"
|
||||||
|
|
||||||
while ! $PSQL -d postgres -c "" 2> /dev/null; do
|
while ! $PSQL -d postgres -c "" 2> /dev/null; do
|
||||||
@ -368,6 +361,14 @@ in
|
|||||||
'') user.ensurePermissions)}
|
'') user.ensurePermissions)}
|
||||||
'') cfg.ensureUsers}
|
'') cfg.ensureUsers}
|
||||||
'';
|
'';
|
||||||
|
in
|
||||||
|
"+${setupScript}";
|
||||||
|
}
|
||||||
|
(mkIf (cfg.dataDir == "/var/lib/postgresql/${cfg.package.psqlSchema}") {
|
||||||
|
StateDirectory = "postgresql postgresql/${cfg.package.psqlSchema}";
|
||||||
|
StateDirectoryMode = if groupAccessAvailable then "0750" else "0700";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
unitConfig.RequiresMountsFor = "${cfg.dataDir}";
|
unitConfig.RequiresMountsFor = "${cfg.dataDir}";
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user