matrix-synapse: restart service on restore #1630

Merged
clan-bot merged 2 commits from clan-name into main 2024-06-17 12:30:03 +00:00
3 changed files with 10 additions and 1 deletions

View File

@ -63,5 +63,10 @@
output = machine.succeed("runuser -u postgres -- /run/current-system/sw/bin/psql --csv -c \"SELECT datdba::regrole FROM pg_database WHERE datname = 'test'\"") output = machine.succeed("runuser -u postgres -- /run/current-system/sw/bin/psql --csv -c \"SELECT datdba::regrole FROM pg_database WHERE datname = 'test'\"")
owner = output.split("\n")[1] owner = output.split("\n")[1]
assert owner == "test", f"Expected database owner to be 'test', got '{owner}'" assert owner == "test", f"Expected database owner to be 'test', got '{owner}'"
# check if restore works if the database does not exist
machine.succeed("runuser -u postgres -- dropdb test")
machine.succeed("${nodes.machine.clanCore.state.postgresql-test.postRestoreCommand}")
machine.succeed("runuser -u postgres -- /run/current-system/sw/bin/psql -d test -c '\dt' >&2")
''; '';
}) })

View File

@ -147,6 +147,7 @@ in
ENCODING = "UTF8"; ENCODING = "UTF8";
OWNER = "matrix-synapse"; OWNER = "matrix-synapse";
}; };
clan.postgresql.databases.matrix-synapse.restore.stopOnRestore = [ "matrix-synapse" ];
clanCore.facts.services = clanCore.facts.services =
{ {

View File

@ -146,6 +146,7 @@ in
pkgs.coreutils pkgs.coreutils
pkgs.util-linux pkgs.util-linux
pkgs.zstd pkgs.zstd
pkgs.gnugrep
] ]
} }
while [[ "$(systemctl is-active postgresql)" == activating ]]; do while [[ "$(systemctl is-active postgresql)" == activating ]]; do
@ -167,7 +168,9 @@ in
} }
mkdir -p "${folder}" mkdir -p "${folder}"
runuser -u postgres -- dropdb "${db.name}" if runuser -u postgres -- psql -d postgres -c "SELECT 1 FROM pg_database WHERE datname = '${db.name}'" | grep -q 1; then
runuser -u postgres -- dropdb "${db.name}"
fi
runuser -u postgres -- pg_restore -C -d postgres "${current}" runuser -u postgres -- pg_restore -C -d postgres "${current}"
) )
else else