source: main/trunk/greenstone2/bin/script/activate.pl@ 25675

Last change on this file since 25675 was 25675, checked in by ak19, 12 years ago
  1. Can run the ant target to get the library_URL for GS3 from anywhere, thanks to Sam's suggestion of the -buildfile parameter to ant, 2. gs_mode is set to gs2 when a collect.cfg exists even when there's a collectionConfig.xml. Now the presence of a site parameter to the activate.pl script is used to finally decide the version of the Greenstone.
  • Property svn:executable set to *
File size: 24.1 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# activate.pl -- to be called after building a collection to activate it.
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 2009 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29
30# This program is designed to support the building process of Greenstone.
31# It deactivates the collection just built, if the web server is running
32# and is a persistent web server (or if the library_URL provided as
33# parameter to this script is of a currently running web server). It then
34# moves building to index, before activating the collection on the GS2 or
35# GS3 web server again if necessary.
36
37
38BEGIN {
39 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
40 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
41 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
42}
43
44
45use strict;
46no strict 'refs'; # allow filehandles to be variables and vice versa
47no strict 'subs'; # allow barewords (eg STDERR) as function arguments
48
49use File::Basename;
50use File::Find;
51
52use HTTP::Response;
53use LWP::Simple qw($ua !head); # import useragent object as $ua from the full LWP to use along with LWP::Simple
54 # don't import LWP::Simple's head function by name since it can conflict with CGI:head())
55#use CGI qw(:standard); # then only CGI.pm defines a head()
56use Net::Ping;
57use URI;
58
59use colcfg;
60use scriptutil;
61use util;
62#use enum;
63
64# enumerations in perl, http://stackoverflow.com/questions/473666/does-perl-have-an-enumeration-type
65# Unfortunately, not part of perl's core
66#use enum qw(LEVEL_NONE LEVEL_ERROR LEVEL_INFO LEVEL_DEBUG); # debugging levels NONE == 0, ERROR=1 INFO=2 DEBUG=3
67
68# global variables
69#my $default_verbosity = LEVEL_ERROR; # by default we display basic error messages
70
71my $default_verbosity = 2; # by default we display basic error and info messages
72
73sub print_task_msg {
74 my ($task_msg, $verbosity_setting) = @_;
75
76 $verbosity_setting = $default_verbosity unless $verbosity_setting;
77 #$verbosity_setting = 1 unless defined $verbosity;
78 if($verbosity_setting >= 1) {
79 print STDERR "\n";
80 print STDERR "************************\n";
81 print STDERR "* $task_msg\n";
82 print STDERR "************************\n";
83 }
84}
85
86# Prints messages if the verbosity is right. Does not add new lines.
87sub print_msg {
88 my ($msg, $min_verbosity, $verbosity_setting) = @_;
89
90 # only display error messages if the current
91 # verbosity setting >= the minimum verbosity level
92 # needed for that message to be displayed.
93
94 $verbosity_setting = $default_verbosity unless defined $verbosity_setting;
95 $min_verbosity = 1 unless defined $min_verbosity;
96 if($verbosity_setting >= $min_verbosity) { # by default display all 1 messages
97 print STDERR "$msg";
98 }
99}
100
101# Method to send a command to a GS2 or GS3 library_URL
102# the commands used in this script can be activate, deactivate, ping,
103# and is-persistent (is-persistent only implemented for GS2).
104sub config {
105 my ($library_url, $command, $check_message_against_regex, $site) = @_;
106 # Gatherer.java's configGS3Server doesn't use the site variable
107 # so we don't have to either
108
109 # for GS2, getting the HTTP status isn't enough, we need to read the output
110 # since this is what CollectionManager.config() stipulates.
111 # Using LWP::UserAgent::get($url) for this
112
113 if(!defined $library_url) {
114 return 0;
115 }
116 else {
117 $ua->timeout(5); # set LWP useragent to 5s max timeout for testing the URL
118 # Need to set this, else it takes I don't know how long to timeout
119 # http://www.perlmonks.org/?node_id=618534
120
121 # http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/UserAgent.pm
122 # use LWP::UserAgent's get($url) since it returns an HTTP::Response code
123
124 my $response_obj = $ua->get( $library_url.$command);
125
126 # $response_obj->content stores the content and $response_obj->code the HTTP response code
127 my $response_code = $response_obj->code();
128
129 if(LWP::Simple::is_success($response_code)) {# $response_code eq RC_OK) { # LWP::Simple::is_success($response_code)
130 &print_msg("*** Command $library_url$command\n", 3);
131 &print_msg("*** HTTP Response Status: $response_code - Complete.", 3);
132
133 # check the page content is as expected
134 my $response_content = $response_obj->content;
135 if($response_content =~ m/$check_message_against_regex/) {
136 &print_msg(" Response as expected.\n", 3);
137 return 1;
138 } else {
139 &print_msg("\n\tBUT: command $library_url$command response UNEXPECTED.\n", 3);
140 &print_msg("*** Got message:\n$response_content.\n", 4);
141 return 0; # ping on a collection may "not succeed."
142 }
143 }
144 elsif(LWP::Simple::is_error($response_code)) { # method exported by LWP::Simple, along with HTTP::Status constants
145 &print_msg("*** Command $library_url$command\n");
146 &print_msg("*** HTTP Response Status: $response_code - Failed.\n");
147 return 0;
148 }
149 }
150}
151
152sub deactivate_collection {
153 my ($library_url, $gs_mode, $qualified_collection, $site) = @_;
154
155 if($gs_mode eq "gs2") {
156 my $DEACTIVATE_COMMAND = "?a=config&cmd=release-collection&c=";
157 my $check_message_against_regex = q/configured release-collection/;
158 config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
159 }
160 elsif ($gs_mode eq "gs3") {
161 my $DEACTIVATE_COMMAND = "?a=s&sa=d&st=collection&sn=";
162 my $check_message_against_regex = "collection: $qualified_collection deactivated";
163 config($library_url, $DEACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
164 }
165}
166
167sub activate_collection {
168 my ($library_url, $gs_mode, $qualified_collection, $site) = @_;
169
170 if($gs_mode eq "gs2") {
171 my $ACTIVATE_COMMAND = "?a=config&cmd=add-collection&c=";
172 my $check_message_against_regex = q/configured add-collection/;
173 config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex);
174 }
175 elsif ($gs_mode eq "gs3") {
176 my $ACTIVATE_COMMAND = "?a=s&sa=a&st=collection&sn=";
177 my $check_message_against_regex = "collection: $qualified_collection activated";
178 config($library_url, $ACTIVATE_COMMAND.$qualified_collection, $check_message_against_regex, $site);
179 }
180}
181
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.
191sub ping_library {
192 my ($library_url, $gs_mode, $site) = @_;
193
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);
217}
218
219# return true if server is persistent, by calling is-persistent on library_url
220# this is only for GS2, since the GS3 server is always persistent
221sub is_persistent {
222 my ($library_url, $gs_mode) = @_;
223
224 if($gs_mode eq "gs3") { # GS3 server is always persistent
225 return 1;
226 }
227
228 my $command = "?a=is-persistent";
229 my $check_responsemsg_against_regex = q/true/; # isPersistent: true versus isPersistent: false
230 return config($library_url, $command, $check_responsemsg_against_regex);
231}
232
233sub get_library_URL {
234 my $gs_mode = shift(@_); # gs3 or gs2
235
236 # If we get here, we are dealing with a server included with GS.
237 # For GS3, we ask ant for the library URL.
238 # For GS2, we derive the URL from the llssite.cfg file.
239
240 my $url = undef;
241
242 if($gs_mode eq "gs2") {
243 my $llssite_cfg = &util::filename_cat($ENV{'GSDLHOME'}, "llssite.cfg");
244
245 if(-f $llssite_cfg) {
246 # check llssite.cfg for line with url property
247 # for server.exe also need to use portnumber and enterlib properties
248
249 # Read in the entire contents of the file in one hit
250 if (!open (FIN, $llssite_cfg)) {
251 &print_msg("activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n");
252 return undef;
253 }
254
255 my $contents;
256 sysread(FIN, $contents, -s FIN);
257 close(FIN);
258
259 my @lines = split(/[\n\r]+/, $contents); # split on carriage-returns and/or linefeeds
260 my $enterlib = "";
261 my $portnumber = ""; # will remain empty (implicit port 80) unless it's specifically been assigned
262
263 foreach my $line (@lines) {
264 if($line =~ m/^url=(.*)$/) {
265 $url = $1;
266 } elsif($line =~ m/^enterlib=(.*)$/) {
267 $enterlib = $1;
268 } elsif($line =~ m/^portnumber=(.*)$/) {
269 $portnumber = $1;
270 }
271 }
272
273 if(!$url) {
274 return undef;
275 }
276 elsif($url eq "URL_pending") { # library is not running
277 # do not process url=URL_pending in the file, since for server.exe
278 # this just means the Enter Library button hasn't been pressed yet
279 $url = undef;
280 }
281 else {
282 # In the case of server.exe, need to do extra work to get the proper URL
283 # But first, need to know whether we're indeed dealing with server.exe:
284
285 # compare the URL's domain to the full URL
286 # E.g. for http://localhost:8383/greenstone3/cgi-bin, the domain is localhost:8383
287 my $uri = URI->new( $url );
288 my $host = $uri->host;
289 #print STDERR "@@@@@ host: $host\n";
290 if($url =~ m/http:\/\/$host(\/)?$/) {
291 #if($url !~ m/http:\/\/$host:$portnumber(\/)?/ || $url =~ m/http:\/\/$host(\/)?$/) {
292 # (if the URL does not contain the portnumber, OR if the port is implicitly 80 and)
293 # If the domain with http:// prefix is completely the same as the URL, assume server.exe
294 # then the actual URL is the result of suffixing the port and enterlib properties in llssite.cfg
295 $url = $url.":".$portnumber.$enterlib;
296 } # else, apache web server
297
298 }
299 }
300 } elsif($gs_mode eq "gs3") {
301 # Either check build.properties for tomcat.server, tomcat.port and app.name (and default servlet name).
302 # app.name is stored in app.path by build.xml. Need to move app.name in build.properties from build.xml
303
304 # Or, run the new target get-default-servlet-url
305 # the output can look like:
306 #
307 # Buildfile: build.xml
308 # [echo] os.name: Windows Vista
309 #
310 # get-default-servlet-url:
311 # [echo] http://localhost:8383/greenstone3/library
312 # BUILD SUCCESSFUL
313 # Total time: 0 seconds
314
315 #my $output = qx/ant get-default-servlet-url/; # backtick operator, to get STDOUT (else 2>&1)
316 # see http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec
317
318 # The get-default-servlet-url ant target can be run from anywhere by specifying the
319 # location of GS3's ant build.xml buildfile. Activate.pl can be run from anywhere for GS3
320 # GSDL3SRCHOME will be set for GS3 by gs3-setup.sh, a step that would have been necessary
321 # to run the activate.pl script in the first place
322 my $perl_command = "ant -buildfile \"$ENV{'GSDL3SRCHOME'}/build.xml\" get-default-servlet-url";
323
324 if (open(PIN, "$perl_command |")) {
325 while (defined (my $perl_output_line = <PIN>)) {
326 if($perl_output_line =~ m@http:\/\/(\S*)@) { # grab all the non-whitespace chars
327 $url="http://".$1;
328 }
329 }
330 close(PIN);
331 } else {
332 &print_msg("activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n");
333 }
334 }
335
336 # either the url is still undef or it is now set
337 #print STDERR "\n@@@@@ final URL:|$url|\n" if $url;
338 #print STDERR "\n@@@@@ URL still undef\n" if !$url;
339 return $url;
340}
341
342### UNUSED METHODS TO MOVE TO util.pm?
343
344# This method is now unused. Using ping_library instead to send the ping action to a
345# GS2/GS3 server. This method can be used more generally to test whether a URL is alive.
346# http://search.cpan.org/dist/libwww-perl/lib/LWP/Simple.pm
347# and http://www.perlmonks.org/?node_id=618534
348sub is_URL_active {
349 my $url = shift(@_); # gs3 or gs2 URL
350
351 my $status = 0;
352 if(defined $url) {
353 $ua->timeout(5); # set LWP useragent to 5s max timeout for testing the URL
354 # Need to set this, else it takes I don't know how long to timeout
355 # http://www.perlmonks.org/?node_id=618534
356
357 $status = LWP::Simple::head($url); # returns empty list of headers if it fails
358 # LWP::Simple::get($url) is more intensive, so don't need to do that
359 #print STDERR "**** $url is alive.\n" if $status;
360 }
361 return $status;
362}
363
364# Pinging seems to always return true, so this method doesn't work
365sub pingHost {
366 my $url = shift(@_); # gs3 or gs2 URL
367
368 my $status = 0;
369 if(defined $url) {
370 # Get just the domain. "http://localhost/gsdl?uq=332033495" becomes "localhost"
371 # "http://localhost/greenstone/cgi-bin/library.cgi" becomes "localhost" too
372
373 #my $host = $url;
374 #$host =~ s@^http:\/\/(www.)?@@;
375 #$host =~ s@\/.*@@;
376 #print STDERR "**** HOST: $host\n";
377
378 # More robust way
379 # http://stackoverflow.com/questions/827024/how-do-i-extract-the-domain-out-of-an-url
380 my $uri = URI->new( $url );
381 my $host = $uri->host;
382
383 # Ping the host. http://perldoc.perl.org/Net/Ping.html
384 my $p = Net::Ping->new();
385 $status = $p->ping($host); # || 0. Appears to set to undef rather than 0
386 print STDERR "**** $host is alive.\n" if $status; #print "$host is alive.\n" if $p->ping($host);
387 $p->close();
388 }
389 # return whether pinging was a success or failure
390 return $status;
391}
392
393
394# Most of the arguments are familiar from the building scripts like buildcol.pl
395# The special optional argument -library_url is for when we're dealing with a web
396# library server such as an apache that's separate from any included with GS2.
397# In such a case, this script's caller should pass in -library_url <URL>.
398#
399# $site argument must be specified in the cmdline for collectionConfig.xml to get
400# generated which makes $gs_mode=gs3, else collect.cfg gets generated and $gs_mode=gs2
401sub main
402{
403 my ($argc,@argv) = @_;
404
405 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
406 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
407
408
409 print STDERR "\n";
410 print STDERR "Usage: $progname [-collectdir c -builddir b -indexdir i -site s -removeold -keepold -verbosity v\n";
411 print STDERR "\t-library_url URL] <[colgroup/]collection>\n";
412 print STDERR "\n";
413
414 exit(-1);
415 }
416
417 # get the collection details
418 my $qualified_collection = pop @argv; # qualified collection
419
420 my $collect_dir = "collect"; # undef
421 my $build_dir = undef;
422 my $index_dir = undef;
423 my $site = undef;
424
425 my $removeold = 0;
426 my $keepold = 0;
427
428 my $library_url = undef; # to be specified on the cmdline if not using a GS-included web server
429
430 while (my $arg = shift @argv) {
431 if ($arg eq "-collectdir") {
432 $collect_dir = shift @argv;
433 }
434 elsif ($arg eq "-builddir") {
435 $build_dir = shift @argv;
436 }
437 elsif ($arg eq "-indexdir") {
438 $index_dir = shift @argv;
439 }
440 elsif ($arg eq "-site") {
441 $site = shift @argv;
442 }
443 elsif ($arg eq "-removeold") {
444 $removeold = 1;
445 }
446 elsif ($arg eq "-keepold") {
447 $keepold = 1;
448 }
449 elsif ($arg eq "-library_url") {
450 $library_url = shift @argv;
451 }
452 elsif ($arg eq "-verbosity") {
453 $default_verbosity = shift @argv; # global variable
454
455 # ensure we're working with ints not strings (int context not str context), in case verbosity=0
456 # http://stackoverflow.com/questions/288900/how-can-i-convert-a-string-to-a-number-in-perl
457 $default_verbosity = int($default_verbosity || 0); ### is this the best way?
458 }
459 }
460
461 # work out the building and index dirs
462 my $collection_dir = &util::resolve_collection_dir($collect_dir, $qualified_collection, $site);
463 $build_dir = &util::filename_cat($collection_dir, "building") unless (defined $build_dir);
464 $index_dir = &util::filename_cat($collection_dir, "index") unless (defined $index_dir);
465
466 &print_task_msg("Running Collection Activation Stage");
467
468 # can't do anything without a build directory with something in it to move into index
469 if(!&util::dir_exists($build_dir)) {
470 &print_msg("No building folder at $build_dir to move to index.\n");
471 exit -1;
472 } elsif (&util::is_dir_empty($build_dir)) {
473 &print_msg("Nothing in building folder $build_dir to move into index folder.\n");
474 exit -1;
475 }
476
477 # get and check the collection name
478 if ((&colcfg::use_collection($site, $qualified_collection, $collect_dir)) eq "") {
479 &print_msg("Unable to use collection \"$qualified_collection\" within \"$collect_dir\"\n");
480 exit -1;
481 }
482
483 # Read in the collection configuration file.
484 # Beware: Only if $site is specified in the cmdline does collectionConfig.xml get
485 # generated and does $gs_mode=gs3, else collect.cfg gets generated and $gs_mode=gs2
486 my ($collect_cfg_filename, $gs_mode) = &colcfg::get_collect_cfg_name(STDERR);
487 my $collectcfg = &colcfg::read_collection_cfg ($collect_cfg_filename,$gs_mode);
488
489 # look for build.cfg/buildConfig.xml
490 my $build_cfg_filename ="";
491
492 if ($gs_mode eq "gs2") {
493 $build_cfg_filename = &util::filename_cat($build_dir,"build.cfg");
494 } else {
495 $build_cfg_filename = &util::filename_cat($build_dir, "buildConfig.xml");
496 # gs_mode is GS3. Set the site now if this was not specified as cmdline argument
497 #$site = "localsite" unless defined $site;
498 }
499
500 # We would like to know what the buildtype is
501 # This will be useful for Solr.
502 if (-e $build_cfg_filename) {
503
504 # testing if there has been a change of indexer
505 # (e.g. collect.cfg now says lucene, but build.cfg says mgpp)
506 my $buildcfg = &colcfg::read_building_cfg ($build_cfg_filename, $gs_mode);
507 if ($buildcfg->{'buildtype'} ne $collectcfg->{'buildtype'}) {
508 ### do something? See incremental-buildcol.pl
509 }
510 else {
511 ### do something? See incremental-buildcol.pl
512 }
513 }
514 else { # build.cfg doesn't exist
515 ### do something? See incremental-buildcol.pl
516 }
517
518 # gs_mode is set to gs2 if there's a collect.cfg and regardless of whether there's a collectionConfig.xml
519 # (this happens especially when a GS2 collection is being converted to GS3).
520 # override this behaviour here, by looking for whether a site variable was passed in
521 if(defined $site && $gs_mode eq "gs2") {
522 $gs_mode="gs3";
523 }
524
525 # Now the logic in GLI's CollectionManager.java (processComplete()
526 # and installCollection()) and Gatherer.configGS3Server().
527
528 # 1. Get library URL
529
530 # For web servers that are external to a Greenstone installation,
531 # the user can pass in their web server's library URL.
532 # For web servers included with GS (like tomcat for GS3 and server.exe
533 # and apache for GS2), we work out the library URL:
534 if(!$library_url) {
535 $library_url = &get_library_URL($gs_mode); # returns undef if no server is running
536 }
537
538 # CollectionManager's installCollection phase in GLI
539 # 2. Ping the library URL, and if it's a persistent server and running, release the collection
540
541 my $is_persistent_server = undef;
542 if($library_url) { # undef if no valid server URL
543
544 &print_msg("Pinging $library_url\n");
545 if(&ping_library($library_url, $gs_mode, $site)) { # server running
546
547 # server is running, so release the collection if
548 # the server is persistent and the collection is active
549 &print_msg("Checking if Greenstone server is persistent\n");
550 $is_persistent_server = &is_persistent($library_url, $gs_mode);
551
552 if($is_persistent_server) { # only makes sense to issue activate and deactivate cmds to a persistent server
553
554 &print_msg("Checking if the collection $qualified_collection is already active\n");
555 my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site);
556
557 if($collection_active) {
558 &print_msg("De-activating collection $qualified_collection\n");
559 &deactivate_collection($library_url, $gs_mode, $qualified_collection, $site);
560 }
561 }
562 }
563 }
564
565 # 3. Do all the moving building to index stuff now
566
567 # If removeold: replace index dir with building dir.
568 # If keepold: move building's contents into index, where only duplicates will get deleted.
569 # removeold and keepold can't both be on at the same time
570 ($removeold, $keepold) = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
571 0, # incremental is irrelevant to what activate.pl does, setting this = 0
572 $build_dir, # checkdir. Usually archives or export to be deleted. activate.pl deletes building
573 $collectcfg);
574
575 if($removeold) {
576
577 if(&util::dir_exists($index_dir)) {
578 &print_task_msg("Removing \"index\"");
579 &util::rm_r($index_dir);
580
581 # Wait for a couple of seconds, just for luck
582 sleep 2;
583
584 if (&util::dir_exists($index_dir)) {
585 &print_msg("The index directory $index_dir could not be deleted.\n"); # CollectionManager.Index_Not_Deleted
586 }
587 }
588
589 # if remote GS server: gliserver.pl would call activate.pl to activate
590 # the collection at this point since activate.pl lives on the server side
591
592 # Move the building directory to become the new index directory
593 &print_task_msg("Moving \"building\" -> \"index\"");
594 &util::mv($build_dir, $index_dir);
595 if(&util::dir_exists($build_dir) || !&util::dir_exists($index_dir)) {
596 &print_msg("Could not move $build_dir to $index_dir.\n"); # CollectionManager.Build_Not_Moved
597 }
598 }
599 elsif ($keepold) {
600 # Copy just the contents of building dir into the index dir, overwriting
601 # existing files, but don't replace index with building.
602 &print_task_msg("Moving \"building\" -> \"index\"");
603 &util::mv_dir_contents($build_dir, $index_dir);
604 }
605
606 # 4. Ping the library URL, and if it's a persistent server and running, activate the collection again
607
608 # Check for success: if building does not exist OR is empty
609 if(!&util::dir_exists($build_dir) || &util::is_dir_empty($build_dir)) {
610
611 if($library_url) { # undef if no valid server URL
612
613 &print_msg("Pinging $library_url\n");
614 if(&ping_library($library_url, $gs_mode, $site)) { # server running
615
616 # don't need to work out persistency of server more than once, since the libraryURL hasn't changed
617 if(!defined $is_persistent_server) {
618 &print_msg("Checking if Greenstone server is persistent\n");
619 $is_persistent_server = &is_persistent($library_url, $gs_mode);
620 }
621
622
623 if($is_persistent_server) { # persistent server, so can try activating collection
624
625 &print_msg("Checking if the collection $qualified_collection is not already active\n");
626 my $collection_active = &ping_library_collection($library_url, $gs_mode, $qualified_collection, $site);
627
628 if(!$collection_active) {
629 &print_msg("Activating collection $qualified_collection\n");
630 &activate_collection($library_url, $gs_mode, $qualified_collection, $site);
631 }
632 }
633 }
634 }
635 } else { # installcollection failed
636 #CollectionManager.Preview_Ready_Failed
637 &print_msg("Building directory is not empty or still exists. Failed to properly move $build_dir to $index_dir.\n");
638 }
639}
640
641&main(scalar(@ARGV),@ARGV);
Note: See TracBrowser for help on using the repository browser.