~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to resources/OCF/pgsql

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
            return $OCF_ERR_GENERIC
195
195
        fi
196
196
 
197
 
        if runasowner "$OCF_RESKEY_pgctl $OCF_RESKEY_ctl_opt -D $OCF_RESKEY_pgdata -l $OCF_RESKEY_logfile -o "\'$OCF_RESKEY_start_opt\'" start > /dev/null 2>&1"
 
197
        output=`runasowner "$OCF_RESKEY_pgctl $OCF_RESKEY_ctl_opt -D $OCF_RESKEY_pgdata -l $OCF_RESKEY_logfile -o "\'$OCF_RESKEY_start_opt\'" start" 2>&1`
 
198
 
 
199
        if [ $? -eq 0 ]
198
200
        then
199
201
           # Probably started.....
200
202
            ocf_log info "PostgreSQL start command sent."
201
203
        else
202
 
            ocf_log err "Can't start PostgreSQL."; return $OCF_ERR_GENERIC
 
204
            ocf_log err "Can't start PostgreSQL."
 
205
            echo "$output"
 
206
            return $OCF_ERR_GENERIC
203
207
        fi
204
208
    else
205
209
        ocf_log err "$OCF_RESKEY_pgctl not found!"
206
210
        return $OCF_ERR_GENERIC
207
211
    fi
208
212
 
209
 
    rc=$OCF_ERR_GENERIC
210
 
    while [ $rc -ne 0 ]; do
211
 
        pgsql_monitor
212
 
        rc=$? 
 
213
    while :
 
214
    do
 
215
        pgsql_monitor warn
 
216
        rc=$?
 
217
        if [ $rc -eq 0 ]; then
 
218
            break;
 
219
        fi 
213
220
        sleep 1
214
221
        ocf_log debug "PostgreSQL still hasn't started yet. Waiting..."
215
222
    done
 
223
    ocf_log info "PostgreSQL is started."
216
224
 
217
225
    return $OCF_SUCCESS
218
226
}
224
232
        #Already stopped
225
233
        return $OCF_SUCCESS
226
234
    fi
227
 
    
 
235
 
228
236
    # Stop PostgreSQL do not wait for clients to disconnect
229
 
    runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m fast > /dev/null 2>&1"
 
237
    output=`runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m fast" 2>&1`
230
238
 
231
239
    # stop waiting
232
240
    count=0
245
253
    then
246
254
       #PostgreSQL is still up. Use another shutdown mode.
247
255
       ocf_log info "PostgreSQL failed to stop after ${OCF_RESKEY_stop_escalate}s using -m fast. Trying -m immediate..."
248
 
       runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m immediate > /dev/null 2>&1"
 
256
       echo "$output"
 
257
       output=`runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m immediate" 2>&1`
 
258
       echo "$output"
249
259
    fi
250
260
 
251
 
    rc=$OCF_ERR_GENERIC
252
 
    while [ $rc != $OCF_NOT_RUNNING ]; do
 
261
    while :
 
262
    do
253
263
        pgsql_monitor
254
 
        rc=$? 
 
264
        rc=$?
 
265
        if [ $rc -eq $OCF_NOT_RUNNING ]; then
 
266
            # An unnecessary debug log is prevented.
 
267
            break;
 
268
        fi 
255
269
        sleep 1
256
270
        ocf_log debug "PostgreSQL still hasn't stopped yet. Waiting..."
257
271
    done
283
297
#
284
298
 
285
299
pgsql_monitor() {
 
300
    # Set the log level of the error message
 
301
    loglevel=${1:-err}
 
302
 
286
303
    if ! pgsql_status
287
304
    then
288
305
        ocf_log info "PostgreSQL is down"
291
308
 
292
309
    if [ "x" = "x$OCF_RESKEY_pghost" ]
293
310
    then
294
 
       runasowner "$OCF_RESKEY_psql -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();' >/dev/null 2>&1"
 
311
       output=`runasowner "$OCF_RESKEY_psql -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();'" 2>&1`
295
312
    else
296
 
       runasowner "$OCF_RESKEY_psql -h $OCF_RESKEY_pghost -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();' >/dev/null 2>&1"
 
313
       output=`runasowner "$OCF_RESKEY_psql -h $OCF_RESKEY_pghost -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();'" 2>&1`
297
314
    fi
298
315
    
299
 
    if [ $? -ne  0 ]
 
316
    rc=$?
 
317
    if [ $rc -ne  0 ]
300
318
    then
301
 
        ocf_log err "PostgreSQL $OCF_RESKEY_pgdb isn't running"
 
319
        ocf_log $loglevel "PostgreSQL $OCF_RESKEY_pgdb isn't running"
 
320
        if [ $rc -eq 1 ]
 
321
        then
 
322
            ocf_log err "Fatal error(out of memory or file not found, etc.) occurred while executing the psql command."
 
323
        elif [ $rc -eq 2 ]
 
324
        then
 
325
            ocf_log $loglevel "Connection error(connection to the server went bad and the session was not interactive) occurred while executing the psql command."
 
326
        elif [ $rc -eq 3 ]
 
327
        then
 
328
            ocf_log err "Script error(the variable ON_ERROR_STOP was set) occurred while executing the psql command."
 
329
        fi
 
330
        echo "$output"
302
331
        return $OCF_ERR_GENERIC
303
332
    fi
304
333