2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
1 |
#!/bin/sh
|
8452.3.3
by Karl Fogel
* utilities/: Add copyright header block to source files that were |
2 |
#
|
11555.1.1
by Brad Crittenden
Updated for postgres init scripts in Ubuntu 10.10. Kept old script for convenience. |
3 |
# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
|
8687.15.3
by Karl Fogel
Shorten the copyright header block to two lines. |
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
5 |
|
7379.1.1
by Diogo Matsubara
small change to launchpad-database-setup script so we can create the database using username != matsubara |
6 |
if [ -n "$1" ]; then |
7 |
USER=$1 |
|
8 |
echo "Creating Launchpad database for $USER" |
|
9 |
else
|
|
10224.3.1
by Martin Pool
Better docs in launchpad-database-setup |
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." |
|
7379.1.1
by Diogo Matsubara
small change to launchpad-database-setup script so we can create the database using username != matsubara |
14 |
exit 1 |
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
15 |
fi
|
16 |
||
17 |
# This attempts to automate instructions provided on
|
|
10224.3.1
by Martin Pool
Better docs in launchpad-database-setup |
18 |
# https://dev.launchpad.net/DatabaseSetup which are intended for
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
19 |
# initial Launchpad setup on an otherwise unconfigured postgresql instance
|
20 |
||
9650.1.1
by Jeroen Vermeulen
Fix launchpad-database-setup for postgres 8.4. |
21 |
for pgversion in 8.4 8.3 8.2 |
22 |
do
|
|
11555.1.1
by Brad Crittenden
Updated for postgres init scripts in Ubuntu 10.10. Kept old script for convenience. |
23 |
sudo grep -q "^auto" /etc/postgresql/$pgversion/main/start.conf |
24 |
if [ $? -eq 0 ]; then |
|
9650.1.1
by Jeroen Vermeulen
Fix launchpad-database-setup for postgres 8.4. |
25 |
break
|
26 |
fi
|
|
27 |
done
|
|
28 |
||
29 |
if [ -z "$pgversion" ] |
|
30 |
then
|
|
8777.1.1
by Jeroen Vermeulen
It's spelled postgres, not PostGRES. |
31 |
echo "Unable to determine your postgres version." |
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
32 |
exit 1 |
33 |
fi
|
|
34 |
||
9650.1.1
by Jeroen Vermeulen
Fix launchpad-database-setup for postgres 8.4. |
35 |
echo "Using postgres $pgversion" |
36 |
||
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
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" |
|
8777.1.1
by Jeroen Vermeulen
It's spelled postgres, not PostGRES. |
41 |
echo "ensure postgres is running on port 5432." |
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
42 |
fi; |
43 |
||
11568.1.3
by Curtis Hovey
Updated launchpad-database-setup to work in maverick and pre-Maverick envs. |
44 |
if [ -e /etc/init.d/postgresql-$pgversion ]; then |
45 |
sudo /etc/init.d/postgresql-$pgversion stop
|
|
46 |
else
|
|
47 |
# This is Maverick.
|
|
48 |
sudo /etc/init.d/postgresql stop $pgversion
|
|
49 |
fi
|
|
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
50 |
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
51 |
echo Purging postgresql data...
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
52 |
sudo pg_dropcluster $pgversion main --stop-server
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
53 |
echo Re-creating postgresql database...
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
54 |
# Setting locale to C to make the server run in that locale.
|
55 |
LC_ALL=C sudo pg_createcluster $pgversion main --encoding UNICODE |
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
56 |
|
57 |
echo Applying postgresql configuration changes...
|
|
58 |
||
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
59 |
sudo cp -a /etc/postgresql/$pgversion/main/pg_hba.conf \ |
60 |
/etc/postgresql/$pgversion/main/pg_hba.conf.old
|
|
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
61 |
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/pg_hba.conf || \ |
62 |
sudo patch /etc/postgresql/$pgversion/main/pg_hba.conf <<'EOF' |
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
63 |
--- pg_hba.conf 2005-11-02 17:33:08.000000000 -0800
|
64 |
+++ /tmp/pg_hba.conf 2005-11-03 07:32:46.932400423 -0800
|
|
13875.1.2
by William Grant
Fix patch. |
65 |
@@ -58,7 +58,10 @@
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
66 |
# on a non-local interface via the listen_addresses configuration parameter,
|
67 |
# or via the -i or -h command line switches.
|
|
68 |
#
|
|
69 |
-
|
|
70 |
+# Launchpad users
|
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
71 |
+local all all trust
|
72 |
+host all all 127.0.0.1/32 trust
|
|
13875.1.1
by William Grant
Fix launchpad-database-setup to trust IPv6 loopback too. |
73 |
+host all all ::1/128 trust
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
74 |
|
75 |
||
76 |
||
77 |
EOF
|
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
78 |
sudo chown --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \ |
79 |
/etc/postgresql/$pgversion/main/pg_hba.conf
|
|
80 |
sudo chmod --reference=/etc/postgresql/$pgversion/main/pg_hba.conf.old \ |
|
81 |
/etc/postgresql/$pgversion/main/pg_hba.conf
|
|
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
82 |
|
83 |
sudo grep -q Launchpad /etc/postgresql/$pgversion/main/postgresql.conf || \ |
|
84 |
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF' |
|
85 |
||
86 |
##
|
|
87 |
## Launchpad configuration
|
|
88 |
##
|
|
89 |
# Enable launchpad full text searching in database
|
|
90 |
search_path='$user,public,ts2'
|
|
91 |
add_missing_from=false
|
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
92 |
#enable_seqscan=false
|
9760.1.1
by Gavin Panella
By default, don't ask PostgreSQL to log any statements. |
93 |
log_statement='none'
|
7029.3.1
by Henning Eggers
Made launchpad-database-setup to conform to wiki page. |
94 |
log_line_prefix='[%t] %q%u@%d '
|
95 |
fsync = off
|
|
9650.1.1
by Jeroen Vermeulen
Fix launchpad-database-setup for postgres 8.4. |
96 |
|
97 |
EOF
|
|
98 |
||
99 |
if [ "$pgversion" = 8.2 -o "$pgversion" = 8.3 ] |
|
100 |
then
|
|
101 |
sudo grep -q '^[[:space:]]*max_fsm_relations' /etc/postgresql/$pgversion/main/postgresql.conf || \ |
|
102 |
sudo tee -a /etc/postgresql/$pgversion/main/postgresql.conf <<'EOF' |
|
7368.4.9
by Guilherme Salgado
make lp-db-setup set a value for max_fsm_relations |
103 |
max_fsm_relations=2000
|
6269.5.1
by Mark Shuttleworth
Generalise launchpad-database-setup for pg8.3 |
104 |
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
105 |
EOF
|
9650.1.1
by Jeroen Vermeulen
Fix launchpad-database-setup for postgres 8.4. |
106 |
fi
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
107 |
|
11568.1.3
by Curtis Hovey
Updated launchpad-database-setup to work in maverick and pre-Maverick envs. |
108 |
if [ -e /etc/init.d/postgresql-$pgversion ]; then |
109 |
sudo /etc/init.d/postgresql-$pgversion start
|
|
110 |
else
|
|
111 |
# This is Maverick.
|
|
112 |
sudo /etc/init.d/postgresql start $pgversion
|
|
113 |
fi
|
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
114 |
|
115 |
echo Waiting 10 seconds for postgresql to come up... |
|
116 |
sleep 10
|
|
117 |
||
7379.1.1
by Diogo Matsubara
small change to launchpad-database-setup script so we can create the database using username != matsubara |
118 |
echo Creating postgresql user $USER |
119 |
sudo -u postgres /usr/lib/postgresql/$pgversion/bin/createuser -a -d $USER |
|
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
120 |
|
121 |
echo
|
|
122 |
echo Looks like everything went ok.
|
|
3024.1.2
by Christian Reis
Fix up launchpad-database-setup to cope with a modern PostgreSQL. Patch by Matt Zimmerman <mdz@canonical.com> |
123 |
echo Now run '"make schema"' at the top level of the launchpad tree. |
2778.1.2
by Matt Zimmerman
Add utilities/launchpad-database-setup, which automates most of |
124 |
|
125 |
exit 0 |