Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
terminate-psql-sessions: Rely on the caller to set PGHOST, PGUSER.
Anders Kaseorgfa2496c229e1
diff --git a/scripts/setup/postgres-init-db b/scripts/setup/postgres-init-dbindex fcee219eb96..016349a50a3 100755--- a/scripts/setup/postgres-init-db+++ b/scripts/setup/postgres-init-db@@ -33,7 +33,8 @@ if [ -e "/var/run/supervisor.sock" ]; thenfi# Drop any open connections to any old database.-"$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base+su -s /usr/bin/env - -- "$POSTGRES_USER" \+ "$(dirname "$0")/terminate-psql-sessions" zulip zulip_base(cd / # Make sure the current working directory is readable by postgresdiff --git a/scripts/setup/restore-backup b/scripts/setup/restore-backupindex 432cf4a61c7..15446778ed1 100755--- a/scripts/setup/restore-backup+++ b/scripts/setup/restore-backup@@ -84,17 +84,17 @@ def restore_backup(tarball_file: IO[bytes]) -> None:db_dir = os.path.join(tmp, "zulip-backup", "database")os.setresuid(0, 0, 0)run(["chown", "-R", POSTGRES_USER, "--", tmp])+ as_postgres = ["su", "-s", "/usr/bin/env", "-", "--", POSTGRES_USER]run([+ *as_postgres,os.path.join(settings.DEPLOY_ROOT, "scripts", "setup", "terminate-psql-sessions",),"zulip",- "zulip","zulip_base",],)- as_postgres = ["su", "-s", "/usr/bin/env", "-", "--", POSTGRES_USER]run(as_postgres + ["dropdb", "--if-exists", "--", db_name])run(as_postgres + ["createdb", "-O", "zulip", "-T", "template0", "--", db_name])diff --git a/scripts/setup/terminate-psql-sessions b/scripts/setup/terminate-psql-sessionsindex c6340d270ca..f952eae14d8 100755--- a/scripts/setup/terminate-psql-sessions+++ b/scripts/setup/terminate-psql-sessions@@ -1,32 +1,12 @@#!/usr/bin/env bashset -e-POSTGRES_USER="postgres"-if [ "$(uname)" = "OpenBSD" ]; then- POSTGRES_USER="_postgresql"-fi-cd /-username=$1--shifttables="$(printf "'%s'," "${@//\'/\'\'}")"tables="${tables%,}"-case "$(id -un)" in-root)- psql=(su -s /usr/bin/env - -- "$POSTGRES_USER" psql postgres "$POSTGRES_USER")- ;;-"$POSTGRES_USER")- psql=(psql postgres "$POSTGRES_USER")- ;;-*)- psql=(psql -h localhost postgres "$username")- ;;-esac--"${psql[@]}" -v ON_ERROR_STOP=1 <<EOF+psql postgres -v ON_ERROR_STOP=1 <<EOFSELECT pg_terminate_backend(s.pid)FROM pg_stat_activity s, pg_roles rWHEREdiff --git a/tools/rebuild-dev-database b/tools/rebuild-dev-databaseindex cedca211e36..68baf634fa9 100755--- a/tools/rebuild-dev-database+++ b/tools/rebuild-dev-database@@ -2,7 +2,8 @@set -eset -x-"$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip zulip_base+PGHOST=localhost PGUSER=zulip \+ "$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip_basepsql -v ON_ERROR_STOP=1 -e -h localhost postgres zulip <<EOFDROP DATABASE IF EXISTS zulip;diff --git a/tools/rebuild-test-database b/tools/rebuild-test-databaseindex a6e9214d6b6..990552d8d49 100755--- a/tools/rebuild-test-database+++ b/tools/rebuild-test-database@@ -22,7 +22,8 @@ EOFmkdir -p zerver/tests/fixtures-"$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template+PGHOST=localhost PGUSER=zulip \+ "$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip_test zulip_test_base zulip_test_templatecreate_zulip_testdiff --git a/tools/setup/generate-fixtures b/tools/setup/generate-fixturesindex b77aec85ac9..11a02894ccf 100755--- a/tools/setup/generate-fixtures+++ b/tools/setup/generate-fixtures@@ -3,7 +3,8 @@ set -erun(){- "$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template+ PGHOST=localhost PGUSER=zulip \+ "$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip_test zulip_test_base zulip_test_templatepsql -v ON_ERROR_STOP=1 -h localhost postgres zulip_test << EOFDROP DATABASE IF EXISTS zulip_test;CREATE DATABASE zulip_test TEMPLATE zulip_test_template;diff --git a/tools/setup/postgres-init-dev-db b/tools/setup/postgres-init-dev-dbindex c0cc6b1c35d..7e3cb90330c 100755--- a/tools/setup/postgres-init-dev-db+++ b/tools/setup/postgres-init-dev-db@@ -93,7 +93,8 @@ elsefichmod go-rw ~/.pgpass-"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" "$USERNAME" "$DBNAME" "$DBNAME_BASE"+PGHOST=localhost PGUSER="$USERNAME" \+ "$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" "$DBNAME" "$DBNAME_BASE"psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOFDROP DATABASE IF EXISTS $DBNAME;