Index: /gs2-extensions/tdb-edit/trunk/src/perllib/dbutil/tdbserver.pm
===================================================================
--- /gs2-extensions/tdb-edit/trunk/src/perllib/dbutil/tdbserver.pm	(revision 26084)
+++ /gs2-extensions/tdb-edit/trunk/src/perllib/dbutil/tdbserver.pm	(revision 26085)
@@ -69,53 +69,56 @@
   my $server_lockfile_path =  &util::filename_cat($ENV{'GSDLHOME'},'collect',$collection,'tmp','tdbserver.lock');
   #rint " * Searching for lockfile: " . $server_lockfile_path . "\n";
-  # We need to lock here to ensure only one thread enters the following code,
-  # sees a missing TDBServer, and launches it
-  my $tmp_lockfile_path = &util::filename_cat($ENV{'GSDLHOME'},'tmp','dbutil-tdbserver.lock');
-  open(TMPFH, '>', $tmp_lockfile_path) or die ("Error! Failed to open file for writing: " . $tmp_lockfile_path . "\nReason: " . $! . "\n");
-  flock(TMPFH, LOCK_EX) or die("Error! Cannot lock file exclusively: " . $tmp_lockfile_path . "\nReason: " . $! . "\n");
-  print TMPFH localtime();
-  # - If the file doesn't exist...
   if (!-e $server_lockfile_path)
   {
-    # ...start it!
-    my $launch_cmd = 'TDBServer.pl "' . $$ . '" "' . $collection . '"';
-    print "* Starting TDBServer for: " . $collection . " [" . $launch_cmd . "]\n";
-    # @note I once had the below pipe ending with 2>&1 |, but that then blocks
-    #       indefinitely when looping and reading <SERVERIN>.
-    open(SERVERIN, $launch_cmd . ' |') or die("Error! Failed to run launch command: " . $launch_cmd . "\nReason: " . $! . "\n");
-    # read all the output from the server
-    my $line = '';
-    my $server_lock_file_created = 0;
-    while ($line = <SERVERIN>)
-    {
-      # - watch for the line indicating a lock file has been created and
-      #   populated with a sexy port number
-      if ($line =~ /Server now listening/)
-      {
-        $server_lock_file_created = 1;
-      }
-      # - we could also watch for errors here
-      if ($debug)
-      {
-        if ($line !~ /\n/)
+    # We need to lock here to ensure only one thread enters the following code,
+    # sees a missing TDBServer, and launches it
+    my $tmp_lockfile_path = &util::filename_cat($ENV{'GSDLHOME'},'tmp','dbutil-tdbserver.lock');
+    open(TMPFH, '>', $tmp_lockfile_path) or die("Warning! Failed to open file for writing: " . $tmp_lockfile_path . "\nReason: " . $! . "\n");
+    flock(TMPFH, LOCK_EX) or die("Error! Cannot lock file exclusively: " . $tmp_lockfile_path . "\nReason: " . $! . "\n");
+    print TMPFH localtime();
+    # - If the file still doesn't exist...
+    if (!-e $server_lockfile_path)
+    {
+      # ...start it!
+      my $launch_cmd = 'TDBServer.pl "' . $$ . '" "' . $collection . '"';
+      print "* Starting TDBServer for: " . $collection . " [" . $launch_cmd . "]\n";
+      # @note I once had the below pipe ending with 2>&1 |, but that then blocks
+      #       indefinitely when looping and reading <SERVERIN>.
+      open(SERVERIN, $launch_cmd . ' |') or die("Error! Failed to run launch command: " . $launch_cmd . "\nReason: " . $! . "\n");
+      # read all the output from the server
+      my $line = '';
+      my $server_lock_file_created = 0;
+      while ($line = <SERVERIN>)
+      {
+        # - watch for the line indicating a lock file has been created and
+        #   populated with a sexy port number
+        if ($line =~ /Server now listening/)
         {
-          $line .= "\n";
+          $server_lock_file_created = 1;
         }
-        $|++; # autoflush
-        print "[tdbserver] $line";
-        $|--; # disable autoflush
-      }
-    }
-    close(SERVERIN);
-    if (!$server_lock_file_created)
-    {
-      die("Error! TDBServer failed to create lock file. Check server logs.");
-    }
-    # record this for later
-    $created_server_lockfile_paths{$server_lockfile_path} = 1;
-  }
-  flock(TMPFH, LOCK_UN);
-  close($tmp_lockfile_path);
-  unlink($tmp_lockfile_path);
+        # - we could also watch for errors here
+        if ($debug)
+        {
+          if ($line !~ /\n/)
+          {
+            $line .= "\n";
+          }
+          $|++; # autoflush
+          print "[tdbserver] $line";
+          $|--; # disable autoflush
+        }
+      }
+      close(SERVERIN);
+      if (!$server_lock_file_created)
+      {
+        die("Error! TDBServer failed to create lock file. Check server logs.");
+      }
+      # record this for later
+      $created_server_lockfile_paths{$server_lockfile_path} = 1;
+    }
+    flock(TMPFH, LOCK_UN);
+    close($tmp_lockfile_path);
+    unlink($tmp_lockfile_path);
+  }
   # record this for later
   $listener_server_lockfile_paths{$server_lockfile_path} = $infodb_file_path;
