Changeset 26085

Show
Ignore:
Timestamp:
09.08.2012 10:32:51 (7 years ago)
Author:
jmt12
Message:

Trying to file locking doesn't really work over NFS, and so the code in here to check if a TDBServer is already running (which attempts to get a flock over the tdbserver.lock file) often dies. I've already restructured things so I know a server is running (the Greenstone instance that calls the OpenMPI code starts one) so I don't really need extra testing here - I'll just add a simple file exists test

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb-edit/trunk/src/perllib/dbutil/tdbserver.pm

    r25410 r26085  
    6969  my $server_lockfile_path =  &util::filename_cat($ENV{'GSDLHOME'},'collect',$collection,'tmp','tdbserver.lock'); 
    7070  #rint " * Searching for lockfile: " . $server_lockfile_path . "\n"; 
    71   # We need to lock here to ensure only one thread enters the following code, 
    72   # sees a missing TDBServer, and launches it 
    73   my $tmp_lockfile_path = &util::filename_cat($ENV{'GSDLHOME'},'tmp','dbutil-tdbserver.lock'); 
    74   open(TMPFH, '>', $tmp_lockfile_path) or die ("Error! Failed to open file for writing: " . $tmp_lockfile_path . "\nReason: " . $! . "\n"); 
    75   flock(TMPFH, LOCK_EX) or die("Error! Cannot lock file exclusively: " . $tmp_lockfile_path . "\nReason: " . $! . "\n"); 
    76   print TMPFH localtime(); 
    77   # - If the file doesn't exist... 
    7871  if (!-e $server_lockfile_path) 
    7972  { 
    80     # ...start it! 
    81     my $launch_cmd = 'TDBServer.pl "' . $$ . '" "' . $collection . '"'; 
    82     print "* Starting TDBServer for: " . $collection . " [" . $launch_cmd . "]\n"; 
    83     # @note I once had the below pipe ending with 2>&1 |, but that then blocks 
    84     #       indefinitely when looping and reading <SERVERIN>. 
    85     open(SERVERIN, $launch_cmd . ' |') or die("Error! Failed to run launch command: " . $launch_cmd . "\nReason: " . $! . "\n"); 
    86     # read all the output from the server 
    87     my $line = ''; 
    88     my $server_lock_file_created = 0; 
    89     while ($line = <SERVERIN>) 
    90     { 
    91       # - watch for the line indicating a lock file has been created and 
    92       #   populated with a sexy port number 
    93       if ($line =~ /Server now listening/) 
    94       { 
    95         $server_lock_file_created = 1; 
    96       } 
    97       # - we could also watch for errors here 
    98       if ($debug) 
    99       { 
    100         if ($line !~ /\n/) 
     73    # We need to lock here to ensure only one thread enters the following code, 
     74    # sees a missing TDBServer, and launches it 
     75    my $tmp_lockfile_path = &util::filename_cat($ENV{'GSDLHOME'},'tmp','dbutil-tdbserver.lock'); 
     76    open(TMPFH, '>', $tmp_lockfile_path) or die("Warning! Failed to open file for writing: " . $tmp_lockfile_path . "\nReason: " . $! . "\n"); 
     77    flock(TMPFH, LOCK_EX) or die("Error! Cannot lock file exclusively: " . $tmp_lockfile_path . "\nReason: " . $! . "\n"); 
     78    print TMPFH localtime(); 
     79    # - If the file still doesn't exist... 
     80    if (!-e $server_lockfile_path) 
     81    { 
     82      # ...start it! 
     83      my $launch_cmd = 'TDBServer.pl "' . $$ . '" "' . $collection . '"'; 
     84      print "* Starting TDBServer for: " . $collection . " [" . $launch_cmd . "]\n"; 
     85      # @note I once had the below pipe ending with 2>&1 |, but that then blocks 
     86      #       indefinitely when looping and reading <SERVERIN>. 
     87      open(SERVERIN, $launch_cmd . ' |') or die("Error! Failed to run launch command: " . $launch_cmd . "\nReason: " . $! . "\n"); 
     88      # read all the output from the server 
     89      my $line = ''; 
     90      my $server_lock_file_created = 0; 
     91      while ($line = <SERVERIN>) 
     92      { 
     93        # - watch for the line indicating a lock file has been created and 
     94        #   populated with a sexy port number 
     95        if ($line =~ /Server now listening/) 
    10196        { 
    102           $line .= "\n"; 
     97          $server_lock_file_created = 1; 
    10398        } 
    104         $|++; # autoflush 
    105         print "[tdbserver] $line"; 
    106         $|--; # disable autoflush 
    107       } 
    108     } 
    109     close(SERVERIN); 
    110     if (!$server_lock_file_created) 
    111     { 
    112       die("Error! TDBServer failed to create lock file. Check server logs."); 
    113     } 
    114     # record this for later 
    115     $created_server_lockfile_paths{$server_lockfile_path} = 1; 
    116   } 
    117   flock(TMPFH, LOCK_UN); 
    118   close($tmp_lockfile_path); 
    119   unlink($tmp_lockfile_path); 
     99        # - we could also watch for errors here 
     100        if ($debug) 
     101        { 
     102          if ($line !~ /\n/) 
     103          { 
     104            $line .= "\n"; 
     105          } 
     106          $|++; # autoflush 
     107          print "[tdbserver] $line"; 
     108          $|--; # disable autoflush 
     109        } 
     110      } 
     111      close(SERVERIN); 
     112      if (!$server_lock_file_created) 
     113      { 
     114        die("Error! TDBServer failed to create lock file. Check server logs."); 
     115      } 
     116      # record this for later 
     117      $created_server_lockfile_paths{$server_lockfile_path} = 1; 
     118    } 
     119    flock(TMPFH, LOCK_UN); 
     120    close($tmp_lockfile_path); 
     121    unlink($tmp_lockfile_path); 
     122  } 
    120123  # record this for later 
    121124  $listener_server_lockfile_paths{$server_lockfile_path} = $infodb_file_path;