--- loncom/lonsql 2001/04/02 20:10:09 1.29 +++ loncom/lonsql 2001/04/16 13:47:50 1.32 @@ -23,7 +23,6 @@ sub wanted { push(@metalist,"$dir/$_"); } - $childmaxattempts=10; $run =0;#running counter to generate the query-id @@ -39,6 +38,20 @@ while ($configline=) { } close(CONFIG); +# ------------------------------------- Make sure that database can be accessed +{ + my $dbh; + unless ( + $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0}) + ) { + print "Cannot connect to database!\n"; + exit; + } + else { + $dbh->disconnect; + } +} + # --------------------------------------------- Check if other instance running my $pidfile="$perlvar{'lonDaemons'}/logs/lonsql.pid"; @@ -60,7 +73,6 @@ while ($configline=) { chomp($ip); $hostip{$ip}=$id; - if ($id eq $perlvar{'lonHostID'}) { $thisserver=$name; } $PREFORK++; @@ -191,8 +203,9 @@ sub make_new_child { #open database handle # making dbh global to avoid garbage collector unless ( - $dbh = DBI->connect("DBI:mysql:loncapa","www","123",{ RaiseError =>0,PrintError=>0}) + $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0}) ) { + sleep(10+int(rand(20))); &logthis("WARNING: Couldn't connect to database ($st secs): $@"); print "database handle error\n"; exit;