Fix running postgres-init-db via a relative path.

If the user runs ./scripts/setup/postgres-init-db, then dirname "$0"
would no longer refer to the correct directory after cd /.
This commit is contained in:
Reid Barton 2015-12-22 13:43:20 -05:00 committed by Tim Abbott
parent fd66d9f703
commit 64a142f0a2
1 changed files with 5 additions and 3 deletions

View File

@ -2,9 +2,6 @@
set -e set -e
set -x set -x
# Make sure the current working directory is readable
cd /
# Shut down all services to ensure a quiescent state. # Shut down all services to ensure a quiescent state.
supervisorctl stop all supervisorctl stop all
@ -12,6 +9,10 @@ supervisorctl stop all
# source because postgres user can't read /root/zulip/scripts/setup. # source because postgres user can't read /root/zulip/scripts/setup.
source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base
(
# Make sure the current working directory is readable by postgres
cd /
su postgres -c psql <<EOF su postgres -c psql <<EOF
CREATE USER zulip; CREATE USER zulip;
ALTER ROLE zulip SET search_path TO zulip,public; ALTER ROLE zulip SET search_path TO zulip,public;
@ -23,6 +24,7 @@ su postgres -c 'psql zulip' <<EOF
CREATE SCHEMA zulip AUTHORIZATION zulip; CREATE SCHEMA zulip AUTHORIZATION zulip;
CREATE EXTENSION tsearch_extras SCHEMA zulip; CREATE EXTENSION tsearch_extras SCHEMA zulip;
EOF EOF
)
# Clear memcached to avoid contamination from previous database state # Clear memcached to avoid contamination from previous database state
sh "$(dirname "$0")/flush-memcached" sh "$(dirname "$0")/flush-memcached"