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.
This commit is contained in:
Alex Vandiver 2024-04-03 17:20:18 +00:00 committed by Tim Abbott
parent c56dd5ec4d
commit acc94a5f32
1 changed files with 5 additions and 3 deletions

View File

@ -29,8 +29,8 @@ if [ "$(su "$POSTGRES_USER" -c "cd / && psql -v ON_ERROR_STOP=1 -Atc \"SELECT 1
fi fi
# Shut down all services to ensure a quiescent state. # Shut down all services to ensure a quiescent state.
if [ -e "/var/run/supervisor.sock" ]; then if [ -e "/home/zulip/deployments" ]; then
su zulip -c "$(dirname "$0")/../stop-server" su zulip -c "/home/zulip/deployments/current/scripts/stop-server"
fi fi
# Drop any open connections to any old database. # Drop any open connections to any old database.
@ -54,6 +54,8 @@ EOF
fi fi
# Clear memcached to avoid contamination from previous database state # 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" echo "Database created"