--- projects/cms/source/host/ihost-perl/ihost.pl 2001/03/06 08:38:42 1.24 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/03/14 18:00:16 1.27 @@ -10,7 +10,7 @@ # - pjm2@ukc.ac.uk # # $Author: pjm2 $ -# $Id: ihost.pl,v 1.24 2001/03/06 08:38:42 pjm2 Exp $ +# $Id: ihost.pl,v 1.27 2001/03/14 18:00:16 pjm2 Exp $ #------------------------------------------------------------ $| = 1; @@ -33,6 +33,7 @@ use vars qw ( $filter_addr $file_list $fqdn + $pidfile ); if (@ARGV != 2) { @@ -44,6 +45,10 @@ $filter_manager_port = $ARGV[1]; $seq_no = 1; +# write our PID to a file +$pidfile = "/var/tmp/ihost.pid"; +&write_pid(); + &tcp_configure(); &send_udp_packet(); @@ -71,6 +76,8 @@ while (1) { `sleep $delay`; } +# we'll probably never get here... +`rm -f $pidfile`; exit(0); @@ -304,6 +311,7 @@ sub send_tcp_heartbeat() { ) or return; if (!defined $sock) { print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n"; + &tcp_configure(); return; } @@ -317,6 +325,7 @@ sub send_tcp_heartbeat() { if (!$response eq "OK") { close($sock); print "Server gave wrong response to HEARTBEAT: $response\n"; + &tcp_configure(); return; } @@ -327,6 +336,7 @@ sub send_tcp_heartbeat() { if (!$response eq "OK") { close($sock); print "Server gave wrong response to CONFIG: $response\n"; + &tcp_configure(); return; } @@ -337,6 +347,7 @@ sub send_tcp_heartbeat() { if (!$response eq "OK") { close($sock); print "Server gave wrong response to file list: $response\n"; + &tcp_configure(); return; } @@ -346,12 +357,14 @@ sub send_tcp_heartbeat() { chop $response; if ($response eq "ERROR") { close($sock); + print "Server configuration changed. Reconfiguring with filter manager.\n"; &tcp_configure(); return; } if (!$response eq "OK") { close($sock); print "Server gave wrong response to HEARTBEAT: $response\n"; + &tcp_configure(); return; } @@ -362,11 +375,25 @@ sub send_tcp_heartbeat() { if (!$response eq "OK") { close($sock); print "Server gave wrong response to ENDHEARTBEAT: $response\n"; + &tcp_configure(); return; } close($sock); print "^"; + + return; +} + +#----------------------------------------------------------------------- +# write_pid +# Writes the PID (process ID) of this instance to $pidfile. +# This is then used by a seperate script to check (and restart) ihost. +#----------------------------------------------------------------------- +sub write_pid() { + open PID, ">$pidfile"; + print PID $$; + close PID; return; }