Ignore:
Timestamp:
2008-05-22T18:10:44+12:00 (16 years ago)
Author:
ak19
Message:

Updated write_gsdl_xml_file which now uses wget to check for whether the fedora server is ready after having been restarted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/g2futil.pm

    r15605 r15656  
    6666    my $cmd = "$prog $arguments";
    6767
    68     print "*** cmd = $cmd\n";
     68###    print "*** cmd = $cmd\n";
    6969
    7070    if (open(CMD,"$cmd 2>&1 |"))
     
    242242    my ($fedora_host, $collect_dir, $options) = @_;
    243243    my $verbosity = $options->{'verbosity'};
     244    my $hostname = $options->{'hostname'};
     245    my $port     = $options->{'port'};
     246    my $protocol = $options->{'protocol'};
    244247
    245248    print STDERR "Ensuring that a correct gsdl.xml file exists on the Fedora server end\n";
     
    247250
    248251    # 1. Find out which folder to write to: fedora_host or localhost
    249     # whichever contains fedora.xml is the one we want - if none, exit with error value
     252    # whichever contains fedora.xml is the one we want (if none, exit with error value?)
    250253    my $fedora_home = $ENV{'FEDORA_HOME'};
    251254    my $base_path = &util::filename_cat($fedora_home, "tomcat", "conf", "Catalina");
     
    254257    my $xmlFile = &util::filename_cat($host_path, "fedora.xml");
    255258    if (!-e $xmlFile) {
    256     # try seeing if folder localhost contains fedoraXML
     259    # check if the folder localhost contains fedoraXML
    257260    $host_path = &util::filename_cat($base_path, "localhost");
    258261    $xmlFile = &util::filename_cat($host_path, "fedora.xml");
     
    265268    # 2. Construct the string we are going write to the gsdl.xml file
    266269    # a. get the parent directory of collect_dir by removinbg the word
    267     # "collect" from it and any optional OS-type slash at the end.
     270    # "collect" from it and any optional OS-type slash at the end.
     271    # (Path slash direction does not matter here.)
    268272    my $collectParentDir = $collect_dir;
    269273    $collectParentDir =~ s/collect(\/|\\)?//;
    270    
    271     #replace \ in path as occurs on Windows with /?
    272     #$collectParentDir =~ s/\\/\//g;
    273     #print STDERR "**** collect's parent dir is: $collectParentDir\n";
    274 
     274 
    275275    # b. Use the collectParentDir to create the contents of gsdl.xml
    276276    my $gsdlXMLcontents = "<?xml version='1.0' encoding='utf-8'?>\n<Context docBase=\"";
     
    330330   
    331331   
    332     # QUESTION:
    333     # Starting up the Fedora server takes a long time. How long should we wait before
    334     # import continues? g2f-import relies on an up-and-running Fedora server to purge the
    335     # collection from it whereas g2f-build.pl needs a ready Fedora server in order to make
    336     # it ingest the FedoraMETS.
    337     # Let's try waiting 10s for the Fedora server to really be up and running after the
    338     # restart so import and build can work without glitches. But how can we check if this
    339     # duration is actually sufficient?
    340     print STDERR "Fedora server restarted. Waiting 10 seconds to ensure the server is ready...\n";
    341     sleep 10;
    342 
     332    # Starting up the Fedora server takes a long time. We need to wait for the server to be
     333    # ready before import can continue, because g2f-import relies on an up-and-running Fedora
     334    # server to purge the collection from it while g2f-build.pl needs a ready Fedora server
     335    # in order to make it ingest the FedoraMETS. Sleeping is not sufficient (#sleep 10;) since
     336    # the subsequent steps depend on a proper server restart.
     337    # Dr Bainbridge's suggestion: test the server is ready with a call to wget.
     338   
     339    # Wget tries to retrieve the fedora search page (protocol://host:port/fedora/search)
     340    # 20 times, waiting 3 seconds between each failed attempt. If it ultimately fails, we
     341    # print a message to the user.
     342    # The wget --spider option makes it check that the page is merely there rather than
     343    # downloading it (see http://www.gnu.org/software/wget/manual/wget.html#Download-Options)
     344    # -q is for quiet, --tries for the number of retries, --waitretry is the number of seconds
     345    # between each attempt. Usually wget returns the contents of the page, but in our case it
     346    # will return 0 for success since we are not downloading.
     347
     348    print STDERR "Fedora server restarted. Waiting for it to become ready...\n";
     349   
     350    # print STDERR "****$protocol://$hostname:$port/fedora/search\n";
     351    my $fedoraServerReady = system("wget -q --spider --waitretry=3 --tries=20 $protocol://$hostname:$port/fedora/search");
     352    if($fedoraServerReady != 0) {
     353    print STDERR "Fedora server is still not ready... ERROR: $!\n";
     354    print "Exit status = ", $status/256, "\n";
     355    die "Exiting....\n";
     356    }
     357   
    343358    # return some indication that things went well
    344359    return "gsdl.xml";
Note: See TracChangeset for help on using the changeset viewer.