From bd1a88c706c6c03c7de3ddabce94bf8f808fe092 Mon Sep 17 00:00:00 2001 From: lissav Date: Thu, 25 Oct 2012 13:57:24 +0000 Subject: [PATCH] check for could not connect to database postgres error on createdb git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14121 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/bin/pgsqlsetup | 50 +++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/xCAT-client/bin/pgsqlsetup b/xCAT-client/bin/pgsqlsetup index d89b6e068..423e0fc95 100755 --- a/xCAT-client/bin/pgsqlsetup +++ b/xCAT-client/bin/pgsqlsetup @@ -609,6 +609,48 @@ sub runpostgrescmd } +#----------------------------------------------------------------------------- + +=head3 runpgcmd_chkoutput + + + Run a commmand as the postgres id + Input: command + Output: return code + Note: this version checks for specific error conditions + +=cut + +#----------------------------------------------------------------------------- +sub runpgcmd_chkoutput +{ + my $orgcmd = shift; + my $rc =0; + my $cmd = "\'"; + $cmd .= $orgcmd; + $cmd .= ' 2>&1'; + $cmd .= "\'"; + + my $retries=0; + while ($retries < 6) { + $retries++; + my @output =`su - postgres -c $cmd`; + if (grep(/could not connect to database postgres/, @output)) { + sleep 5; + $rc=1 + } else { + $rc=0; + foreach my $line (@output) { + print "$line \n"; + } + last; + } + } + return $rc; + + +} + #----------------------------------------------------------------------------- @@ -856,11 +898,13 @@ sub setupxcatdb } else { #Linux $cmd = "$::pgcmddir/createdb $::dbname "; } - &runpostgrescmd($cmd); - if ($? > 0) { + # We need to check the output, because sometimes + # postmaster daemon is not ready at this point to create the database + my $rc = &runpgcmd_chkoutput($cmd); + if ($rc > 0) { xCAT::MsgUtils->message("E", "Failed creating the $::dbname database"); - #exit(1); + exit(1); } if ($::osname eq 'AIX')