Changeset 25581

Show
Ignore:
Timestamp:
11.05.2012 22:59:46 (7 years ago)
Author:
ak19
Message:

activate.pl now has both ping_library and ping_library_collection subroutines. The second one is called to check whether a collection needs to be deactivated or activated (in case it's already active).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/bin/script/activate.pl

    r25579 r25581  
    180180} 
    181181 
    182 # send a pingaction to the GS library 
     182sub ping { 
     183    my ($library_url, $command, $gs_mode, $site) = @_; 
     184     
     185    # "Ping" ... "succeeded" expected on success. (Ping on a collection may "not succeed".)  
     186    my $check_responsemsg_against_regex = q/succeeded/;  
     187    return config($library_url, $command, $check_responsemsg_against_regex, $site); 
     188} 
     189 
     190# send a pingaction to the GS library. General server-level ping. 
    183191sub ping_library { 
    184192    my ($library_url, $gs_mode, $site) = @_; 
    185193     
    186     if($gs_mode eq "gs2") { 
    187         my $command = "?a=ping"; 
    188         # "Ping" ... "succeeded" expected on success. (Ping on a collection may "not succeed".) 
    189         my $check_responsemsg_against_regex = q/succeeded/;  
    190         return config($library_url, $command, $check_responsemsg_against_regex); 
    191     } 
    192     elsif ($gs_mode eq "gs3") { 
    193         my $command = "?a=s&sa=ping"; 
    194         my $check_responsemsg_against_regex = "Ping succeeded."; # no other ping response messages even exist for GS3 
    195         config($library_url, $command, $check_responsemsg_against_regex, $site); 
    196     }    
     194    my $command = ""; 
     195    if($gs_mode eq "gs2") {      
     196        $command = "?a=ping";        
     197    } 
     198    elsif ($gs_mode eq "gs3") {      
     199        $command = "?a=s&sa=ping"; 
     200    } 
     201    return &ping($library_url, $command, $gs_mode, $site); 
     202} 
     203 
     204 
     205# send a pingaction to a collection in GS library to check if it's active 
     206sub ping_library_collection { 
     207    my ($library_url, $gs_mode, $qualified_collection, $site) = @_; 
     208     
     209    my $command = ""; 
     210    if($gs_mode eq "gs2") {      
     211        $command = "?a=ping&c=$qualified_collection"; 
     212    } 
     213    elsif ($gs_mode eq "gs3") {      
     214        $command = "?a=s&sa=ping&st=collection&sn=$qualified_collection";        
     215    } 
     216    return &ping($library_url, $command, $gs_mode, $site); 
    197217} 
    198218 
     
    511531     
    512532    my $is_persistent_server = undef; 
    513     if($library_url) { # running server 
    514         &print_msg("Pinging $library_url\n"); 
    515         if($library_url && &ping_library($library_url, $gs_mode, $site)) { 
    516             # server is running, so release the collection if the server is persistent 
     533    if($library_url) { # undef if no valid server URL 
     534     
     535        &print_msg("Pinging $library_url\n");        
     536        if(&ping_library($library_url, $gs_mode, $site)) { # server running 
     537         
     538            # server is running, so release the collection if  
     539            # the server is persistent and the collection is active 
    517540            &print_msg("Checking if Greenstone server is persistent\n"); 
    518             $is_persistent_server = &is_persistent($library_url, $gs_mode);      
    519             if($is_persistent_server) { 
     541            $is_persistent_server = &is_persistent($library_url, $gs_mode); 
     542             
     543            &print_msg("Checking if the collection $qualified_collection is already active\n"); 
     544            my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site); 
     545             
     546            if($is_persistent_server && $collection_active) { 
    520547                &print_msg("De-activating collection $qualified_collection\n"); 
    521548                &deactivate_collection($library_url, $gs_mode, $qualified_collection, $site); 
     
    523550        } 
    524551    } 
     552     
    525553    # 3. Do all the moving building to index stuff now   
    526554 
     
    564592    } 
    565593     
    566      
    567594    # 4. Ping the library URL, and if it's a persistent server and running, activate the collection again    
    568595     
    569596    # Check for success: if building does not exist OR is empty  
    570597    if(!&util::dir_exists($build_dir) || &util::is_dir_empty($build_dir)) { 
    571         if($library_url) { # undef if no server is running 
     598     
     599        if($library_url) { # undef if no valid server URL 
     600         
    572601            &print_msg("Pinging $library_url\n"); 
    573             if(&ping_library($library_url, $gs_mode, $site)) { 
    574                 # don't need to work out persistency of server more than once 
     602            if(&ping_library($library_url, $gs_mode, $site)) { # server running 
     603             
     604                # don't need to work out persistency of server more than once, since the libraryURL hasn't changed               
    575605                if(!defined $is_persistent_server) { 
    576606                    &print_msg("Checking if Greenstone server is persistent\n"); 
    577607                    $is_persistent_server = &is_persistent($library_url, $gs_mode); 
    578                 }    
    579                 if($is_persistent_server) { 
     608                } 
     609                 
     610                &print_msg("Checking if the collection $qualified_collection is not already active\n");              
     611                my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site);                  
     612                     
     613                if($is_persistent_server && !$collection_active) {                   
    580614                    &print_msg("Activating collection $qualified_collection\n"); 
    581615                    &activate_collection($library_url, $gs_mode, $qualified_collection, $site); 
     
    590624 
    591625&main(scalar(@ARGV),@ARGV); 
    592  
    593  
    594  
    595