ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/ihost.pl
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/ihost.pl (file contents):
Revision 1.22 by pjm2, Thu Mar 1 10:49:27 2001 UTC vs.
Revision 1.27 by pjm2, Wed Mar 14 18:00:16 2001 UTC

# Line 33 | Line 33 | use vars qw (
33               $filter_addr
34               $file_list
35               $fqdn
36 +             $pidfile
37              );
38  
39   if (@ARGV != 2) {
# Line 44 | Line 45 | $filter_manager_port = $ARGV[1];
45  
46   $seq_no = 1;
47  
48 + # write our PID to a file
49 + $pidfile = "/var/tmp/ihost.pid";
50 + &write_pid();
51 +
52   &tcp_configure();
53   &send_udp_packet();
54  
# Line 71 | Line 76 | while (1) {
76      `sleep $delay`;
77   }
78  
79 + # we'll probably never get here...
80 + `rm -f $pidfile`;
81   exit(0);
82  
83  
# Line 151 | Line 158 | sub tcp_configure() {
158      
159      print $sock "FILTER\n";
160      $response = <$sock>;
161 +    unless (defined($response)) {
162 +        print "Failed: Could not get a filter address from the filter manager.\n";
163 +        exit(1);
164 +    }
165      chop $response;
166      $response =~ /(.*);(.*);(.*)/;
167      ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3);
168 +    unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) {
169 +        print "Failed: Filter address response from server did not make sense: $response\n";
170 +        exit(1);
171 +    }
172      
173      print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n";
174  
# Line 296 | Line 311 | sub send_tcp_heartbeat() {
311                                      ) or return;
312      if (!defined $sock) {
313          print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n";
314 +        &tcp_configure();
315          return;
316      }
317  
# Line 304 | Line 320 | sub send_tcp_heartbeat() {
320  
321      print $sock "HEARTBEAT\n";
322      $response = <$sock>;
323 <    chop $response or return;
323 >    return if (!defined $response);
324 >    chop $response;
325      if (!$response eq "OK") {
326          close($sock);
327          print "Server gave wrong response to HEARTBEAT: $response\n";
328 +        &tcp_configure();
329          return;
330      }
331      
332      print $sock "CONFIG\n";
333      $response = <$sock>;
334 <    chop $response or return;
334 >    return if (!defined $response);
335 >    chop $response;
336      if (!$response eq "OK") {
337          close($sock);
338          print "Server gave wrong response to CONFIG: $response\n";
339 +        &tcp_configure();
340          return;
341      }
342  
343      print $sock "$file_list\n";
344      $response = <$sock>;
345 <    chop $response or return;
345 >    return if (!defined $response);
346 >    chop $response;
347      if (!$response eq "OK") {
348          close($sock);
349          print "Server gave wrong response to file list: $response\n";
350 +        &tcp_configure();
351          return;
352      }
353      
354      print $sock "$last_modified\n";
355      $response = <$sock>;
356 <    chop $response or return;
356 >    return if (!defined $response);
357 >    chop $response;
358      if ($response eq "ERROR") {
359          close($sock);
360 +        print "Server configuration changed.  Reconfiguring with filter manager.\n";
361          &tcp_configure();
362          return;
363      }
364      if (!$response eq "OK") {
365          close($sock);
366          print "Server gave wrong response to HEARTBEAT: $response\n";
367 +        &tcp_configure();
368          return;
369      }
370      
371      print $sock "ENDHEARTBEAT\n";
372 <    $response = <$sock> or return;
372 >    $response = <$sock>;
373 >    return if (!defined $response);
374      chop $response;
375      if (!$response eq "OK") {
376          close($sock);
377          print "Server gave wrong response to ENDHEARTBEAT: $response\n";
378 +        &tcp_configure();
379          return;
380      }
381      
382      close($sock);
383      print "^";
384 +    
385 +    return;
386 + }
387 +
388 + #-----------------------------------------------------------------------
389 + # write_pid
390 + # Writes the PID (process ID) of this instance to $pidfile.
391 + # This is then used by a seperate script to check (and restart) ihost.
392 + #-----------------------------------------------------------------------
393 + sub write_pid() {
394 +    open PID, ">$pidfile";
395 +    print PID $$;
396 +    close PID;
397      
398      return;
399   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines