mirror of https://github.com/zulip/zulip.git
postgres-init-db: Fix invocation from a relative path.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
cd43a33783
commit
fd2d642f95
|
@ -10,14 +10,12 @@ set -x
|
|||
# What user should we use for connecting to the database
|
||||
POSTGRES_USER="${POSTGRES_USER:-postgres}"
|
||||
|
||||
# We pipe this output through cat to ensure we always get return code 0
|
||||
# We have to do this because on production database zulip may not exist, so psql
|
||||
# will fail with return code 2. Because set -e is on, this will cause the script
|
||||
# to bail.
|
||||
records=$(su "$POSTGRES_USER" -c "psql -v ON_ERROR_STOP=1 -Atc 'SELECT COUNT(*) FROM zulip.zerver_message;' zulip" | cat)
|
||||
|
||||
if [[ $records -gt 200 ]]
|
||||
then
|
||||
# This psql command may fail because the zulip database doesn’t exist,
|
||||
# hence the &&.
|
||||
if records="$(
|
||||
cd / # Make sure the current working directory is readable by postgres
|
||||
su "$POSTGRES_USER" -c "psql -v ON_ERROR_STOP=1 -Atc 'SELECT COUNT(*) FROM zulip.zerver_message;' zulip"
|
||||
)" && [ "$records" -gt 200 ]; then
|
||||
set +x
|
||||
echo "WARNING: This will delete your Zulip database which currently contains $records messages."
|
||||
read -p "Do you want to proceed? [y/N] " -r
|
||||
|
@ -34,18 +32,13 @@ if [ -e "/var/run/supervisor.sock" ]; then
|
|||
supervisorctl stop all
|
||||
fi
|
||||
|
||||
# Drop any open connections to any old database. Hackishly call using
|
||||
# `source`, because postgres user may not be able to read this directory
|
||||
# if unpacked by root.
|
||||
# shellcheck source=terminate-psql-sessions
|
||||
source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base
|
||||
# Drop any open connections to any old database.
|
||||
"$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base
|
||||
|
||||
(
|
||||
# Make sure the current working directory is readable by postgres
|
||||
cd /
|
||||
|
||||
su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e' < "$(dirname "$0")/create-db.sql"
|
||||
)
|
||||
cd / # Make sure the current working directory is readable by postgres
|
||||
su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e'
|
||||
) < "$(dirname "$0")/create-db.sql"
|
||||
|
||||
# Clear memcached to avoid contamination from previous database state
|
||||
"$(dirname "$0")/flush-memcached"
|
||||
|
|
Loading…
Reference in New Issue