2015-09-28 19:45:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
set -x
|
2013-02-25 21:46:36 +01:00
|
|
|
|
2015-10-15 04:47:35 +02:00
|
|
|
# Shut down all services to ensure a quiescent state.
|
2016-04-27 00:20:06 +02:00
|
|
|
if [ -e "/var/run/supervisor.sock" ]; then
|
|
|
|
supervisorctl stop all
|
|
|
|
fi
|
2015-10-15 04:47:35 +02:00
|
|
|
|
2015-09-28 19:45:35 +02:00
|
|
|
# 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
|
|
|
|
|
2015-12-22 19:43:20 +01:00
|
|
|
(
|
|
|
|
# Make sure the current working directory is readable by postgres
|
|
|
|
cd /
|
|
|
|
|
2013-11-13 02:32:52 +01:00
|
|
|
su postgres -c psql <<EOF
|
|
|
|
CREATE USER zulip;
|
|
|
|
ALTER ROLE zulip SET search_path TO zulip,public;
|
|
|
|
DROP DATABASE IF EXISTS zulip;
|
2013-11-13 04:29:49 +01:00
|
|
|
CREATE DATABASE zulip OWNER=zulip;
|
2013-02-25 21:46:36 +01:00
|
|
|
EOF
|
|
|
|
|
2015-08-28 19:40:29 +02:00
|
|
|
su postgres -c 'psql zulip' <<EOF
|
2015-08-28 18:37:46 +02:00
|
|
|
CREATE SCHEMA zulip AUTHORIZATION zulip;
|
2015-08-21 07:17:25 +02:00
|
|
|
CREATE EXTENSION tsearch_extras SCHEMA zulip;
|
|
|
|
EOF
|
2015-12-22 19:43:20 +01:00
|
|
|
)
|
2015-08-21 07:17:25 +02:00
|
|
|
|
2015-09-28 19:45:35 +02:00
|
|
|
# Clear memcached to avoid contamination from previous database state
|
2015-09-28 19:57:40 +02:00
|
|
|
sh "$(dirname "$0")/flush-memcached"
|
|
|
|
|
2013-02-25 21:46:36 +01:00
|
|
|
echo "Database created"
|
|
|
|
|