11555.1.1
by Brad Crittenden
Updated for postgres init scripts in Ubuntu 10.10. Kept old script for convenience. |
1 |
#!/bin/sh
|
2 |
#
|
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
6 |
if [ -n "$1" ]; then |
|
7 |
USER=$1 |
|
8 |
echo "Creating Launchpad database for $USER" |
|
9 |
else
|
|
10 |
echo "usage: launchpad-database-setup DEVELOPER_USER" |
|
11 |
echo "THIS SCRIPT WILL DESTROY ALL POSTGRESQL DATA for the given user" |
|
12 |
echo "If you really want that, run it with the username of your " |
|
13 |
echo "local developer account." |
|
14 |
exit 1 |
|
15 |
fi
|
|
16 |
||
17 |
# This attempts to automate instructions provided on
|
|
18 |
# https://dev.launchpad.net/DatabaseSetup which are intended for
|
|
19 |
# initial Launchpad setup on an otherwise unconfigured postgresql instance
|
|
20 |
||
21 |
for pgversion in 8.4 8.3 8.2 |
|
22 |
do
|
|
23 |
if [ -e /etc/init.d/postgresql-$pgversion ] |
|
24 |
then
|
|
25 |
break
|
|
26 |
fi
|
|
27 |
done
|
|
28 |
||
29 |
if [ -z "$pgversion" ] |
|
30 |
then
|
|
31 |
echo "Unable to determine your postgres version." |
|
32 |
exit 1 |
|
33 |
fi
|
|
34 |
||
35 |
echo "Using postgres $pgversion" |
|
36 |
||
37 |
# Make sure that we have the correct version running on port 5432
|
|
38 |
sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf |
|
39 |
if [ $? -ne 0 ]; then |
|
40 |
echo "Please check /etc/postgresql/$pgversion/main/postgresql.conf and" |
|
41 |
echo "ensure postgres is running on port 5432." |
|
42 |
fi; |
|
43 |
||
44 |
sudo /etc/init.d/postgresql-$pgversion stop
|
|
45 |
||
46 |
echo Purging postgresql data...
|
|
47 |
sudo pg_dropcluster $pgversion main --stop-server
|
|
48 |
echo Re-creating postgresql database...
|
|
49 |
# Setting locale to C to make the server run in that locale.
|
|
50 |
LC_ALL=C sudo pg_createcluster $pgversion main --encoding UNICODE |
|
51 |
||
52 |
echo Applying postgresql configuration changes...
|
|
53 |
||
54 |
sudo cp -a /etc/postgresql/$pgversion/main/pg_hba.conf \ |
|
55 |
/etc/postgresql/$pgversion/main/pg_hba.conf.old
|
|
56 |
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/pg_hba.conf || \ |
|
57 |
sudo patch /etc/postgresql/$pgversion/main/pg_hba.conf <<'EOF' |
|
58 |
--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
|
|
59 |
+++ /tmp/pg_hba.conf 2005-11-03 07:32:46.932400423 -0800
|
|
60 |
@@ -58,7 +58,9 @@
|
|
61 |
# on a non-local interface via the listen_addresses configuration parameter,
|
|
62 |
# or via the -i or -h command line switches.
|
|
63 |
#
|
|
64 |
-
|
|
65 |
+# Launchpad users
|
|
66 |
+local all all trust
|
|
67 |
+host all all 127.0.0.1/32 trust
|
|
68 |
||
69 |
||
70 |
||
71 |
EOF
|
|
72 |
sudo chown --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \ |
|
73 |
/etc/postgresql/$pgversion/main/pg_hba.conf
|
|
74 |
sudo chmod --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \ |
|
75 |
/etc/postgresql/$pgversion/main/pg_hba.conf
|
|
76 |
||
77 |
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/postgresql.conf || \ |
|
78 |
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF' |
|
79 |
||
80 |
##
|
|
81 |
## Launchpad configuration
|
|
82 |
##
|
|
83 |
# Enable launchpad full text searching in database
|
|
84 |
search_path='$user,public,ts2'
|
|
85 |
add_missing_from=false
|
|
86 |
#enable_seqscan=false
|
|
87 |
log_statement='none'
|
|
88 |
log_line_prefix='[%t] %q%u@%d '
|
|
89 |
fsync = off
|
|
90 |
||
91 |
EOF
|
|
92 |
||
93 |
if [ "$pgversion" = 8.2 -o "$pgversion" = 8.3 ] |
|
94 |
then
|
|
95 |
sudo grep -q '^[[:space:]]*max_fsm_relations' /etc/postgresql/$pgversion/main/postgresql.conf || \ |
|
96 |
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF' |
|
97 |
max_fsm_relations=2000
|
|
98 |
||
99 |
EOF
|
|
100 |
fi
|
|
101 |
||
102 |
sudo /etc/init.d/postgresql-$pgversion start
|
|
103 |
||
104 |
echo Waiting 10 seconds for postgresql to come up... |
|
105 |
sleep 10
|
|
106 |
||
107 |
echo Creating postgresql user $USER |
|
108 |
sudo -u postgres /usr/lib/postgresql/$pgversion/bin/createuser -a -d $USER |
|
109 |
||
110 |
echo
|
|
111 |
echo Looks like everything went ok.
|
|
112 |
echo Now run '"make schema"' at the top level of the launchpad tree. |
|
113 |
||
114 |
exit 0 |