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