Merge lp:~bac/launchpad/lp-db-setup into lp:launchpad

Proposed by Brad Crittenden on 2010-09-17
Status: Merged
Merged at revision: 11570
Proposed branch: lp:~bac/launchpad/lp-db-setup
Merge into: lp:launchpad
Diff against target: 159 lines (+119/-5)
2 files modified
utilities/launchpad-database-setup (+5/-5)
utilities/launchpad-database-setup-pre-maverick (+114/-0)
To merge this branch: bzr merge lp:~bac/launchpad/lp-db-setup
Reviewer Review Type Date Requested Status
Abel Deuring (community) code 2010-09-17 Approve on 2010-09-17
Review via email: mp+35822@code.launchpad.net

Commit Message

Fix launchpad-database-setup to work with postgresql in Maverick.

Description of the Change

Fix the database set-up script to work with postgresql start-up script changes in 10.10. Kept the old one around, too, but I'm unsure if that is a good idea.

Test: Warning, this will blow away your database and you must be on Maverick.
utilities/launchpad-database-setup <your username>

To post a comment you must log in.
Abel Deuring (adeuring) wrote :

This diff data in a diff raised a mental parsing error: Why do I see a diff with a file name outside of the branch? But I could fix it on my own ;)

+--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
++++ /tmp/pg_hba.conf 2005-11-03 07:32:46.932400423 -0800

review: Approve (code)

Preview Diff

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