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.25 by tdb, Mon Mar 12 23:20:43 2001 UTC vs.
Revision 1.31 by pjm2, Thu Mar 15 09:46:18 2001 UTC

# Line 34 | Line 34 | use vars qw (
34               $file_list
35               $fqdn
36               $pidfile
37 +             $retry_wait
38              );
39  
40   if (@ARGV != 2) {
# Line 44 | Line 45 | $filter_manager_addr = $ARGV[0];
45   $filter_manager_port = $ARGV[1];
46  
47   $seq_no = 1;
48 + $retry_wait = 600;
49  
50   # write our PID to a file
51 < $pidfile = "ihost.pid";
51 > $pidfile = "/var/tmp/ihost.pid";
52   &write_pid();
53  
54   &tcp_configure();
# Line 82 | Line 84 | exit(0);
84  
85  
86   #-----------------------------------------------------------------------
87 + # wait_then_retry
88 + # Waits for the period of time specified in $retry_wait, then attempts
89 + # to reconfigure with the server.
90 + #-----------------------------------------------------------------------
91 + sub wait_then_retry() {
92 +    print "Will retry configuration with filter manager in $retry_wait seconds.\n";
93 +    `sleep $retry_wait`;
94 + }
95 +
96 +
97 + #-----------------------------------------------------------------------
98   # tcp_configure
99   # Establishes a TCP connection to the specified i-scream filter manager.
100   # The host then requests details from the server, such as the intervals
# Line 89 | Line 102 | exit(0);
102   #-----------------------------------------------------------------------
103   sub tcp_configure() {
104      
105 <    my($sock) = new IO::Socket::INET(
106 <                                     PeerAddr => $filter_manager_addr,
107 <                                     PeerPort => $filter_manager_port,
108 <                                     Proto => 'tcp'
109 <                                    ) or die "Cannot connect!";
110 <    if (!defined $sock) {
111 <        print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n";
112 <        print "Please check that there is an i-scream server at this address.\n";
113 <        print "Program ended.\n";
114 <        exit(1);
115 <    }
105 >    while (1) {
106 >        my($sock) = new IO::Socket::INET(
107 >                                         PeerAddr => $filter_manager_addr,
108 >                                         PeerPort => $filter_manager_port,
109 >                                         Proto => 'tcp'
110 >                                        ) or die "Cannot connect!";
111 >        if (!defined $sock) {
112 >            print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n";
113 >            print "Please check that there is an i-scream server at this address.\n";
114 >            wait_then_retry();
115 >            next;
116 >        }
117  
118 <    # Now run through the configuration process...
119 <    my($response);
118 >        # Now run through the configuration process...
119 >        my($response);
120      
121 <    print $sock "STARTCONFIG\n";
122 <    $response = <$sock>;
123 <    if (!chop $response eq "OK") {
124 <        print "The i-scream server rejected the STARTCONFIG command.  Terminated.";
125 <        exit(1);
126 <    }
121 >        print $sock "STARTCONFIG\n";
122 >        $response = <$sock>;
123 >        if (!chop $response eq "OK") {
124 >            print "The i-scream server rejected the STARTCONFIG command.  Terminated.";
125 >            close($sock);
126 >            wait_then_retry();
127 >            next;
128 >        }
129  
130 <    print "Config started okay.\n";
130 >        print "Config started okay.\n";
131      
132 <    print $sock "LASTMODIFIED\n";
133 <    $response = <$sock>;
134 <    chop $response;
135 <    $last_modified = $response;
132 >        print $sock "LASTMODIFIED\n";
133 >        $response = <$sock>;
134 >        chop $response;
135 >        $last_modified = $response;
136      
137 <    print "Config last modified: ". (scalar localtime $last_modified/1000) . "\n";
137 >        print "Config last modified: ". (scalar localtime $last_modified/1000) . "\n";
138  
139 <    print $sock "FILELIST\n";
140 <    $response = <$sock>;
141 <    chop $response;
142 <    $file_list = $response;
139 >        print $sock "FILELIST\n";
140 >        $response = <$sock>;
141 >        chop $response;
142 >        $file_list = $response;
143  
144 <    print "File list obtained: $file_list\n";
144 >        print "File list obtained: $file_list\n";
145  
146 <    print $sock "FQDN\n";
147 <    $response = <$sock>;
148 <    chop $response;
149 <    $fqdn = $response;
146 >        print $sock "FQDN\n";
147 >        $response = <$sock>;
148 >        chop $response;
149 >        $fqdn = $response;
150  
151 <    print "FQDN returned: $fqdn\n";
151 >        print "FQDN returned: $fqdn\n";
152  
153 <    print $sock "UDPUpdateTime\n";
154 <    $response = <$sock>;
155 <    chop $response;
156 <    $udp_update_time = $response;
153 >        print $sock "UDPUpdateTime\n";
154 >        $response = <$sock>;
155 >        chop $response;
156 >        $udp_update_time = $response;
157  
158 <    print $sock "TCPUpdateTime\n";
159 <    $response = <$sock>;
160 <    chop $response;
161 <    $tcp_update_time = $response;
158 >        print $sock "TCPUpdateTime\n";
159 >        $response = <$sock>;
160 >        chop $response;
161 >        $tcp_update_time = $response;
162      
163 <    print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time seconds.\n";
163 >        print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time seconds.\n";
164  
165 <    print $sock "ENDCONFIG\n";
166 <    $response = <$sock>;
167 <    chomp $response;
168 <    if (!$response eq "OK") {
169 <        print "ENDCONFIG command to server failed.  Terminated.\n";
170 <        exit(1);
171 <    }
165 >        print $sock "ENDCONFIG\n";
166 >        $response = <$sock>;
167 >        chomp $response;
168 >        if (!$response eq "OK") {
169 >            print "ENDCONFIG command to server failed.  Terminated.\n";
170 >            close($sock);
171 >            wait_then_retry();
172 >            next;
173 >        }
174  
175 <    print "Config ended.\n";
175 >        print "Config ended.\n";
176      
177 <    print $sock "FILTER\n";
178 <    $response = <$sock>;
179 <    unless (defined($response)) {
180 <        print "Failed: Could not get a filter address from the filter manager.\n";
181 <        exit(1);
182 <    }
183 <    chop $response;
184 <    $response =~ /(.*);(.*);(.*)/;
185 <    ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3);
186 <    unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) {
187 <        print "Failed: Filter address response from server did not make sense: $response\n";
188 <        exit(1);
189 <    }
177 >        print $sock "FILTER\n";
178 >        $response = <$sock>;
179 >        unless (defined($response)) {
180 >            print "Failed: Could not get a filter address from the filter manager.\n";
181 >            close($sock);
182 >            wait_then_retry();
183 >            next;
184 >        }
185 >        chop $response;
186 >        $response =~ /(.*);(.*);(.*)/;
187 >        if ($response eq "ERROR") {
188 >            print "There are no active configured filters for your host.\n";
189 >            close($sock);
190 >            wait_then_retry();
191 >            next;
192 >        }
193 >        ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3);
194 >        unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) {
195 >            print "Failed: Filter address response from server did not make sense: $response\n";
196 >            close($sock);
197 >            wait_then_retry();
198 >            next;
199 >        }
200      
201 <    print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n";
201 >        print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n";
202  
203 <    print $sock "END\n";
204 <    $response = <$sock>;
205 <    chop $response;
206 <    if ($response eq "OK") {
207 <        print "Host successfully configured via TCP.\n"
208 <    }
209 <    else {
210 <        print "The server failed the host configuration on the END command.";
211 <        exit(1);
212 <    }
203 >        print $sock "END\n";
204 >        $response = <$sock>;
205 >        chop $response;
206 >        if ($response eq "OK") {
207 >            print "Host successfully configured via TCP.\n"
208 >        }
209 >        else {
210 >            print "The server failed the host configuration on the END command.";
211 >            close($sock);
212 >            wait_then_retry();
213 >            next;
214 >        }
215      
216 <    close($sock);
216 >        close($sock);
217  
218 <    print "Configuration finished sucessfully!\n";
219 <    
218 >        print "Configuration finished sucessfully!\n";
219 >        last;
220 >    }
221      return;
222   }
223  
# Line 311 | Line 342 | sub send_tcp_heartbeat() {
342                                      ) or return;
343      if (!defined $sock) {
344          print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n";
345 +        &tcp_configure();
346          return;
347      }
348  
# Line 324 | Line 356 | sub send_tcp_heartbeat() {
356      if (!$response eq "OK") {
357          close($sock);
358          print "Server gave wrong response to HEARTBEAT: $response\n";
359 +        &tcp_configure();
360          return;
361      }
362      
# Line 334 | Line 367 | sub send_tcp_heartbeat() {
367      if (!$response eq "OK") {
368          close($sock);
369          print "Server gave wrong response to CONFIG: $response\n";
370 +        &tcp_configure();
371          return;
372      }
373  
# Line 344 | Line 378 | sub send_tcp_heartbeat() {
378      if (!$response eq "OK") {
379          close($sock);
380          print "Server gave wrong response to file list: $response\n";
381 +        &tcp_configure();
382          return;
383      }
384      
# Line 353 | Line 388 | sub send_tcp_heartbeat() {
388      chop $response;
389      if ($response eq "ERROR") {
390          close($sock);
391 +        print "Server configuration changed.  Reconfiguring with filter manager.\n";
392          &tcp_configure();
393          return;
394      }
395      if (!$response eq "OK") {
396          close($sock);
397          print "Server gave wrong response to HEARTBEAT: $response\n";
398 +        &tcp_configure();
399          return;
400      }
401      
# Line 369 | Line 406 | sub send_tcp_heartbeat() {
406      if (!$response eq "OK") {
407          close($sock);
408          print "Server gave wrong response to ENDHEARTBEAT: $response\n";
409 +        &tcp_configure();
410          return;
411      }
412      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines