Index: /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl
===================================================================
--- /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl	(revision 24446)
+++ /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl	(revision 24447)
@@ -35,5 +35,4 @@
 # into that needed by the solr server.  
 
-my $jetty_stop_key="greenstone-solr";
 
 BEGIN {
@@ -47,12 +46,10 @@
 use util;
 
-
 # Not quite OO, but close enough for now
 #
 my $self = { 'full_server_jar' => undef,
-##	     'full_post_jar'   = undef,
-##	     'full_index_propfile' = undef,
-	     'jetty_explicitly_started' => undef
-	 };
+	     'jetty_explicitly_started' => undef,
+	     'jetty_stop_key' => "greenstone-solr"
+	     };
 
 
@@ -81,6 +78,7 @@
     my ($search_path) = @_;
 
-    my $solr_home       = $ENV{'GEXT_SOLR'};
-    my $jetty_stop_port = $ENV{'JETTY_STOP_PORT'};
+    my $solr_home         = $ENV{'GEXT_SOLR'};
+    my $jetty_stop_port   = $ENV{'JETTY_STOP_PORT'};
+    my $jetty_server_port = $ENV{'SOLR_JETTY_PORT'};
 
     chdir($solr_home);
@@ -89,5 +87,5 @@
 
     my $server_props = "-DSTOP.PORT=$jetty_stop_port";
-    $server_props .= " -DSTOP.KEY=$jetty_stop_key";
+    $server_props .= " -DSTOP.KEY=".$self->{'jetty_stop_key'};
     $server_props .= " -Dsolr.solr.home=$solr_etc";
 
@@ -97,14 +95,11 @@
     
     my $server_java_cmd = "java $server_props -jar \"$full_server_jar\"";
-#    if ($ENV{'GSDLOS'} eq "windows") {
-#	$server_java_cmd = "start $server_java_cmd";
-#    }
-#    else {
-#	$server_java_cmd .= " &";
-#    }
-    
+
+##    print STDERR "**** server cmd = $server_java_cmd\n";
 
     if (open(SIN,"$server_java_cmd 2>&1 |")) {
 	
+	my $server_status = "unknown";
+
 	my $line;
 	while (defined($line=<SIN>)) {
@@ -113,10 +108,41 @@
 	    # which signifies that the server has started up and is
 	    # "ready and listening"
+
+##	    print STDERR "**** $line";
+
+	    if (($line =~ m/^(WARN|ERROR|SEVERE):/)
+		|| ($line =~ m/^[0-9 :-]*(WARN|ERROR|SEVERE)::/)) {
+		print $line;
+	    }
+
+
+	    if ($line =~ m/WARN::failed SocketConnector/) {
+		if ($line =~ m/Address already in use/) {
+		    $server_status = "already-running";
+		}
+		else {
+		    $server_status = "failed-to-start";
+		}
+		last;
+	    }
+		
+	    if ($line =~ m/INFO::Started SocketConnector/) {
+		$server_status = "explicitly-started";
+		last;
+	    }
+	}
+
+	if ($server_status eq "explicitly-started") {
+	    $self->{'jetty_explicitly_started'} = 1;
+	    print STDERR "Jetty server ready and listening for connections\n";
+	}
+	elsif ($server_status eq "already-running") {
+	    print STDERR "Using existing server detected on port $jetty_server_port\n";
+	}
+	else {
+	    print STDERR "Failed to start Solr/Jetty web server on $jetty_server_port\n";
+	    exit -1;
+	}
 	    
-	    last if ($line =~ m/INFO::Started SocketConnector/);
-	}
-
-	print STDERR "Jetty server ready and listening for connections\n";
-
 	# now we know the server is ready to accept connections, fork a
 	# child process that continues to listen to the output and
@@ -140,5 +166,11 @@
     else {
 	print STDERR "Error: failed to start solr-jetty-server\n";
-	print STDERR "!$\n";
+	print STDERR "!$\n\n";
+	print STDERR "Command attempted was:\n";
+	print STDERR "  $server_java_cmd\n";
+	print STDERR "run from directory:\n";
+	print STDERR "  $solr_home\n";
+	print STDERR "----\n";
+
 	exit -1;
     }
@@ -147,6 +179,4 @@
     # *and* we are the parent process of the fork()
 
-    $self->{'jetty_explicitly_started'} = 1;
-
 }
 
@@ -158,5 +188,6 @@
     my $jetty_stop_port = $ENV{'JETTY_STOP_PORT'};
     
-    my $server_props = "-DSTOP.PORT=$jetty_stop_port -DSTOP.KEY=$jetty_stop_key";
+    my $server_props = "-DSTOP.PORT=$jetty_stop_port";
+    $server_props   .= " -DSTOP.KEY=".$self->{'jetty_stop_key'};
     my $server_java_cmd = "java $server_props -jar \"$full_server_jar\" --stop";
 
@@ -170,4 +201,5 @@
     else {
 	wait(); # let the child process finish
+	print STDERR "Jetty server shutdown\n";
     }
 }
@@ -185,22 +217,4 @@
   }
 
-# No longer used, as solr now run as two cores per collection (-Doc and -Sec)
-#
-#  # Set up an 'index.properties' file in $full_builddir, with the line
-#  #   index=$indexdir
-#  $full_index_propfile = &util::filename_cat($full_builddir,"index.properties");
-
-#  if (open(IPOUT,">$full_index_propfile")) {
-#      print IPOUT "index=$indexdir\n";
-#      close(IPOUT);
-#  }
-#  else {
-#      print STDERR "Failed to create $full_index_propfile\n";
-#      print STDERR "!$\n";
-#      exit -2;
-#  }
-
-  
-
   my $search_path = [];
 
@@ -215,13 +229,10 @@
   start_solr_server($search_path);
 
-
   # Now run the solr-post command
 
   chdir($ENV{'GEXT_SOLR'});
-
   
   my $post_jar   = &util::filename_cat("lib","java","solr-post.jar");
   my $full_post_jar   = locate_file($search_path,$post_jar);
-##  $self->{'full_post_jar'} = $full_post_jar;
 
   my $jetty_server_port = $ENV{'SOLR_JETTY_PORT'};
@@ -234,5 +245,5 @@
   my $post_java_cmd = "java $post_props -jar \"$full_post_jar\"";
 
-  print STDERR "**** post cmd = $post_java_cmd\n";
+###  print STDERR "**** post cmd = $post_java_cmd\n";
   
   open (PIPEOUT, "| $post_java_cmd") 
@@ -250,14 +261,8 @@
 	stop_solr_server();
     }
-
-#  No longer used
-#    # $full_index_propfile is set up as a global variable so it can be shared
-#    # between open_java_solr() and here
-#    &util::rm($full_index_propfile);
-}
-
-
-
-
+}
+
+
+#----
 
 sub save_xml_doc
@@ -418,5 +423,5 @@
   }
   else {
-      print STDERR "Streaming input onto solr server!\n";
+      print STDERR "Streaming document input onto Solr server!\n";
       pass_on_xml_stream();
   }
Index: /gs3-extensions/solr/trunk/src/perllib/solrbuilder.pm
===================================================================
--- /gs3-extensions/solr/trunk/src/perllib/solrbuilder.pm	(revision 24446)
+++ /gs3-extensions/solr/trunk/src/perllib/solrbuilder.pm	(revision 24447)
@@ -320,14 +320,7 @@
 	# to figure out what the metadata_field_mapping is	    
 
-##	my $db_level = "section"; #always
-
 	# set up the document processr
 	$self->{'buildproc'}->set_output_handle (undef);
 	$self->{'buildproc'}->set_mode ('index_field_mapping');
-##	$self->{'buildproc'}->set_index ($index);
-##	$self->{'buildproc'}->set_indexing_text (0);
-	#$self->{'buildproc'}->set_indexfieldmap ($self->{'indexfieldmap'});
-##	$self->{'buildproc'}->set_levels ($levels);
-##	$self->{'buildproc'}->set_db_level ($db_level);
 	$self->{'buildproc'}->reset();
 	
@@ -338,9 +331,4 @@
 	&plugin::end($self->{'pluginfo'});
 	
-##	close ($handle) unless $self->{'debug'};
-
-##	$self->print_stats();
-
-	# just make "delete" stop  ???
     }
 
@@ -373,61 +361,4 @@
 
 }
-
-# Essentially the same as the lucenebuilder.pm version, only using solr_passes
-# => refactor and make better use of inheritence
-
-sub build_indexesXXXX {
-    my $self = shift (@_);
-    my ($indexname) = @_;
-    my $outhandle = $self->{'outhandle'};
-
-    $self->pre_build_indexes($indexname);
-
-    my $indexes = [];
-    if (defined $indexname && $indexname =~ /\w/) {
-	push @$indexes, $indexname;
-    } else {
-	$indexes = $self->{'collect_cfg'}->{'indexes'};
-    }
-
-    # have we got para index?
-    foreach my $level (keys %{$self->{'levels'}}) {
-	if ($level =~ /paragraph/) {
-	    print $outhandle "Warning: Paragraph level indexing not supported by Solr\n";
-	    last;
-	}
-    }
-    # create the mapping between the index descriptions
-    # and their directory names (includes subcolls and langs)
-    $self->{'index_mapping'} = $self->create_index_mapping ($indexes);
-
-    # build each of the indexes
-    foreach my $index (@$indexes) {
-	if ($self->want_built($index)) {
-
-	    my $idx = $self->{'index_mapping'}->{$index};
-	    foreach my $level (keys %{$self->{'levels'}}) {
-		next if $level =~ /paragraph/; # we don't do para indexing
-		my ($pindex) = $level =~ /^(.)/;
-		# should probably check that new name with level
-		# is unique ... but currently (with doc sec and para)
-		# each has unique first letter.
-		$self->{'index_mapping'}->{$index} = $pindex.$idx;
-
-		my $llevel = $mgppbuilder::level_map{$level};
-		print $outhandle "\n*** building index $index at level $llevel in subdirectory " .
-		    "$self->{'index_mapping'}->{$index}\n" if ($self->{'verbosity'} >= 1);
-		print STDERR "<Stage name='Index' source='$index' level=$llevel>\n" if $self->{'gli'};
-
-		$self->build_index($index,$llevel);
-	    }
-	    $self->{'index_mapping'}->{$index} = $idx;
-
-	} else {
-	    print $outhandle "\n*** ignoring index $index\n" if ($self->{'verbosity'} >= 1);
-	}
-    }
-}
-
 
 # Essentially the same as the lucenebuilder.pm version, only using solr_passes
@@ -546,8 +477,4 @@
     print $handle "<update>\n";
 
-    open(TOUT,">/tmp/solr.out"); binmode(TOUT,":utf8");
-    print TOUT "<update>\n";
-    close(TOUT);
-
     &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
 		   "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
@@ -556,8 +483,4 @@
     print $handle "</update>\n";
 
-    open(TOUT,">>/tmp/solr.out"); binmode(TOUT,":utf8");
-    print TOUT "</update>\n";
-    close(TOUT);
-
     close ($handle) unless $self->{'debug'};
 
@@ -568,5 +491,4 @@
 
 }
-
 
 
Index: /gs3-extensions/solr/trunk/src/perllib/solrbuildproc.pm
===================================================================
--- /gs3-extensions/solr/trunk/src/perllib/solrbuildproc.pm	(revision 24446)
+++ /gs3-extensions/solr/trunk/src/perllib/solrbuildproc.pm	(revision 24447)
@@ -556,12 +556,8 @@
     $text .= $end_doc if ($sec_tag_name eq "");
 
-
 ##    $text .= "<commit/>\n";
 
     print $solrhandle $text;
 
-    open(TOUT,">>/tmp/solr.out"); binmode(TOUT,":utf8");
-    print TOUT $text;
-    close(TOUT);
 }
 
