~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/schema/full-update.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-09 09:25:45 UTC
  • mfrom: (7675.1045.776 db-devel)
  • Revision ID: launchpad@pqm.canonical.com-20110909092545-gudc8ixy0xaaz05v
Merging db-stable at revno 10959

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import _pythonpath
8
8
 
9
 
import os.path
 
9
from datetime import datetime
10
10
from optparse import OptionParser
11
11
import subprocess
12
12
import sys
105
105
    # work unattended.
106
106
    #
107
107
 
 
108
    # Confirm we can invoke PGBOUNCER_INITD
 
109
    log.debug("Confirming sudo access to pgbouncer startup script")
 
110
    pgbouncer_rc = run_pgbouncer(log, 'status')
 
111
    if pgbouncer_rc != 0:
 
112
        return pgbouncer_rc
 
113
 
108
114
    # We initially ignore open connections, as they will shortly be
109
115
    # killed.
110
116
    if not NoConnectionCheckPreflight(log).check_all():
111
117
        return 99
112
118
 
113
 
    # Confirm we can invoke PGBOUNCER_INITD
114
 
    pgbouncer_rc = run_pgbouncer(log, 'status')
115
 
    if pgbouncer_rc != 0:
116
 
        return pgbouncer_rc
117
 
 
118
119
    #
119
120
    # Start the actual upgrade. Failures beyond this point need to
120
121
    # generate informative messages to help with recovery.
125
126
    upgrade_run = False
126
127
    security_run = False
127
128
 
 
129
    outage_start = datetime.now()
 
130
 
128
131
    try:
129
132
        # Shutdown pgbouncer
 
133
        log.info("Outage starts. Shutting down pgbouncer.")
130
134
        pgbouncer_rc = run_pgbouncer(log, 'stop')
131
135
        if pgbouncer_rc != 0:
132
136
            log.fatal("pgbouncer not shut down [%s]", pgbouncer_rc)
136
140
        if not KillConnectionsPreflight(log).check_all():
137
141
            return 100
138
142
 
 
143
        log.info("Preflight check succeeded. Starting upgrade.")
139
144
        upgrade_rc = run_upgrade(options, log)
140
145
        if upgrade_rc != 0:
141
146
            return upgrade_rc
142
147
        upgrade_run = True
 
148
        log.info("Database patches applied. Stored procedures updated.")
143
149
 
144
150
        security_rc = run_security(options, log)
145
151
        if security_rc != 0:
148
154
 
149
155
        log.info("All database upgrade steps completed")
150
156
 
 
157
        log.info("Restarting pgbouncer")
151
158
        pgbouncer_rc = run_pgbouncer(log, 'start')
152
159
        if pgbouncer_rc != 0:
153
160
            log.fatal("pgbouncer not restarted [%s]", pgbouncer_rc)
154
161
            return pgbouncer_rc
155
162
        pgbouncer_down = False
 
163
        log.info("Outage complete. %s", datetime.now() - outage_start)
156
164
 
157
165
        # We will start seeing connections as soon as pgbouncer is
158
166
        # reenabled, so ignore them here.
180
188
            pgbouncer_rc = run_pgbouncer(log, 'start')
181
189
            if pgbouncer_rc == 0:
182
190
                log.info("Despite failures, pgbouncer restarted.")
 
191
                log.info("Outage complete. %s", datetime.now() - outage_start)
183
192
            else:
184
193
                log.fatal("pgbouncer is down and refuses to restart")
185
194
        if not upgrade_run: