Merge ~doismellburning/launchpad:bail-on-fail-on-db-setup into launchpad:master

Proposed by Kristian Glass
Status: Merged
Approved by: Kristian Glass
Approved revision: de60cbfe981f9a466cae7495a69c3651103cfddb
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~doismellburning/launchpad:bail-on-fail-on-db-setup
Merge into: launchpad:master
Diff against target: 33 lines (+4/-4)
1 file modified
utilities/launchpad-database-setup (+4/-4)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Colin Watson (community) Approve
Review via email: mp+387647@code.launchpad.net

Commit message

Exit on failure in launchpad-database-setup

Let's avoid:

    Creating postgresql user runner
    createuser: could not connect to database postgres

    Looks like everything went ok.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

This needs other changes further down the script; anywhere that runs a command and then tests $? is going to need to be adjusted to work with set -e.

review: Needs Fixing
Revision history for this message
Kristian Glass (doismellburning) wrote :

Good point, thanks - I don't think I love these variable names, but they should do the job!

Revision history for this message
Colin Watson (cjwatson) wrote :

I normally just use "code" or something similarly not-very-nymous for this sort of thing, but this is fine.

If you prefer, you could also consider this style, which may be neater in this case:

  if sudo grep -qs "^auto" /etc/postgresql/$try_pgversion/main/start.conf; then
    pgversion="$try_pgversion"
    break
  fi

and:

  if ! sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf; then
    echo "..."
  fi

review: Approve
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve
Revision history for this message
Kristian Glass (doismellburning) wrote :

Much neater, thanks Colin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/utilities/launchpad-database-setup b/utilities/launchpad-database-setup
index 0b893de..46a36ce 100755
--- a/utilities/launchpad-database-setup
+++ b/utilities/launchpad-database-setup
@@ -3,6 +3,8 @@
3# Copyright 2009-2012 Canonical Ltd. This software is licensed under the3# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
4# GNU Affero General Public License version 3 (see the file LICENSE).4# GNU Affero General Public License version 3 (see the file LICENSE).
55
6set -e # Exit immediately if a command exits with a non-zero status.
7
6if [ -n "$1" ]; then8if [ -n "$1" ]; then
7 USER=$19 USER=$1
8 echo "Creating Launchpad database for $USER"10 echo "Creating Launchpad database for $USER"
@@ -21,8 +23,7 @@ fi
21pgversion=23pgversion=
22for try_pgversion in 1024for try_pgversion in 10
23do25do
24 sudo grep -qs "^auto" /etc/postgresql/$try_pgversion/main/start.conf26 if sudo grep -qs "^auto" /etc/postgresql/$try_pgversion/main/start.conf; then
25 if [ $? -eq 0 ]; then
26 pgversion="$try_pgversion"27 pgversion="$try_pgversion"
27 break28 break
28 fi29 fi
@@ -37,8 +38,7 @@ fi
37echo "Using postgres $pgversion"38echo "Using postgres $pgversion"
3839
39# Make sure that we have the correct version running on port 543240# Make sure that we have the correct version running on port 5432
40sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf41if ! sudo grep -q "port.*5432" /etc/postgresql/$pgversion/main/postgresql.conf; then
41if [ $? -ne 0 ]; then
42 echo "Please check /etc/postgresql/$pgversion/main/postgresql.conf and"42 echo "Please check /etc/postgresql/$pgversion/main/postgresql.conf and"
43 echo "ensure postgres is running on port 5432."43 echo "ensure postgres is running on port 5432."
44fi;44fi;

Subscribers

People subscribed via source and target branches

to status/vote changes: