Fix race condition
This commit is contained in:
@@ -41,17 +41,23 @@ in {
|
||||
description = "Set DB passwords and ownership after Postgres is ready";
|
||||
after = [ "postgresql.service" ];
|
||||
requires = [ "postgresql.service" ];
|
||||
partOf = [ "postgresql.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "postgres"; # Runs as postgres user directly
|
||||
RemainAfterExit = true;
|
||||
ExecStartPre = "${pkgs.coreutils}/bin/sleep 2";
|
||||
};
|
||||
|
||||
script = ''
|
||||
PSQL="${pkgs.postgresql}/bin/psql"
|
||||
${lib.concatMapStringsSep "\n" (name: ''
|
||||
until $PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname = '${name}_user'" | grep -q 1; do
|
||||
echo "Waiting for user ${name}_user..."
|
||||
sleep 1
|
||||
done
|
||||
$PSQL -tAc "ALTER DATABASE ${name}_db OWNER TO ${name}_user;"
|
||||
|
||||
if [ -f "${config.sops.secrets."${name}_pass".path}" ]; then
|
||||
|
||||
Reference in New Issue
Block a user