#!/bin/bash set -ex # A bit of a helper variable, default is voyager DEPLOYMENT_TYPE="${DEPLOYMENT_TYPE:-voyager}" # What user should we use for connecting to the database POSTGRES_USER="${POSTGRES_USER:-postgres}" # Shut down all services to ensure a quiescent state. # Stop supervisord only if the socket exists, prevents problems with docker if [ -e "/var/run/supervisor.sock" ]; then supervisorctl stop all fi # Don't "terminate" psql sessions when run in docker! if [ "$DEPLOYMENT_TYPE" != "dockervoyager" ]; then # Drop any open connections to any old database. Hackishly call using # source because postgres user can't read /root/zulip/scripts/setup. source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base fi # Create the "connect" command here POSTGRES_COMMAND="psql" if [ ! -z "$DB_HOST" ]; then POSTGRES_COMMAND="$POSTGRES_COMMAND -h $DB_HOST" fi if [ ! -z "$DB_HOST_PORT" ]; then POSTGRES_COMMAND="$POSTGRES_COMMAND -p $DB_HOST_PORT" fi if [ ! -z "$DB_USER" ]; then POSTGRES_COMMAND="$POSTGRES_COMMAND -U $DB_USER" fi if [ ! -z "$DB_PASS" ]; then export PGPASSWORD="$DB_PASS" fi ( # Make sure the current working directory is readable by postgres cd / su "$POSTGRES_USER" -c "$POSTGRES_COMMAND" <