From acc94a5f32310544dab25d1c5e145db602599145 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 3 Apr 2024 17:20:18 +0000 Subject: [PATCH] create-database: Skip stop-server and flush-memcached on standalone Pg. If running on a stand-alone PostgreSQL server, then supervisor does exist -- but `stop-server` is useless, and in fact cannot run because the Zulip directory may not be readable by the `zulip` user. Detect if this is an application front-end server by looking for `/home/zulip/deployments`, and use the stop-server and flush-memcached from there if it exists. The `create-db.sql` and `terminate-psql-sessions` files are still read from the local directory, but those already have precautions from being from a non-world-readable directory, and are more obviously important to keep in sync with the `create-database` script. --- scripts/setup/create-database | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/setup/create-database b/scripts/setup/create-database index 3c3de04ff8..9316133384 100755 --- a/scripts/setup/create-database +++ b/scripts/setup/create-database @@ -29,8 +29,8 @@ if [ "$(su "$POSTGRES_USER" -c "cd / && psql -v ON_ERROR_STOP=1 -Atc \"SELECT 1 fi # Shut down all services to ensure a quiescent state. -if [ -e "/var/run/supervisor.sock" ]; then - su zulip -c "$(dirname "$0")/../stop-server" +if [ -e "/home/zulip/deployments" ]; then + su zulip -c "/home/zulip/deployments/current/scripts/stop-server" fi # Drop any open connections to any old database. @@ -54,6 +54,8 @@ EOF fi # Clear memcached to avoid contamination from previous database state -"$(dirname "$0")/flush-memcached" +if [ -e "/home/zulip/deployments" ]; then + /home/zulip/deployments/current/scripts/setup/flush-memcached +fi echo "Database created"