33 |
|
$filter_addr |
34 |
|
$file_list |
35 |
|
$fqdn |
36 |
+ |
$pidfile |
37 |
|
); |
38 |
|
|
39 |
|
if (@ARGV != 2) { |
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 |
|
|
76 |
|
`sleep $delay`; |
77 |
|
} |
78 |
|
|
79 |
+ |
# we'll probably never get here... |
80 |
+ |
`rm -f $pidfile`; |
81 |
|
exit(0); |
82 |
|
|
83 |
|
|
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 |
|
|
319 |
|
|
320 |
|
print $sock "HEARTBEAT\n"; |
321 |
|
$response = <$sock>; |
322 |
< |
chop $response or return; |
322 |
> |
return if (!defined $response); |
323 |
> |
chop $response; |
324 |
|
if (!$response eq "OK") { |
325 |
|
close($sock); |
326 |
|
print "Server gave wrong response to HEARTBEAT: $response\n"; |
329 |
|
|
330 |
|
print $sock "CONFIG\n"; |
331 |
|
$response = <$sock>; |
332 |
< |
chop $response or return; |
332 |
> |
return if (!defined $response); |
333 |
> |
chop $response; |
334 |
|
if (!$response eq "OK") { |
335 |
|
close($sock); |
336 |
|
print "Server gave wrong response to CONFIG: $response\n"; |
339 |
|
|
340 |
|
print $sock "$file_list\n"; |
341 |
|
$response = <$sock>; |
342 |
< |
chop $response or return; |
342 |
> |
return if (!defined $response); |
343 |
> |
chop $response; |
344 |
|
if (!$response eq "OK") { |
345 |
|
close($sock); |
346 |
|
print "Server gave wrong response to file list: $response\n"; |
349 |
|
|
350 |
|
print $sock "$last_modified\n"; |
351 |
|
$response = <$sock>; |
352 |
< |
chop $response or return; |
352 |
> |
return if (!defined $response); |
353 |
> |
chop $response; |
354 |
|
if ($response eq "ERROR") { |
355 |
|
close($sock); |
356 |
|
&tcp_configure(); |
363 |
|
} |
364 |
|
|
365 |
|
print $sock "ENDHEARTBEAT\n"; |
366 |
< |
$response = <$sock> or return; |
366 |
> |
$response = <$sock>; |
367 |
> |
return if (!defined $response); |
368 |
|
chop $response; |
369 |
|
if (!$response eq "OK") { |
370 |
|
close($sock); |
374 |
|
|
375 |
|
close($sock); |
376 |
|
print "^"; |
377 |
+ |
|
378 |
+ |
return; |
379 |
+ |
} |
380 |
+ |
|
381 |
+ |
#----------------------------------------------------------------------- |
382 |
+ |
# write_pid |
383 |
+ |
# Writes the PID (process ID) of this instance to $pidfile. |
384 |
+ |
# This is then used by a seperate script to check (and restart) ihost. |
385 |
+ |
#----------------------------------------------------------------------- |
386 |
+ |
sub write_pid() { |
387 |
+ |
open PID, ">$pidfile"; |
388 |
+ |
print PID $$; |
389 |
+ |
close PID; |
390 |
|
|
391 |
|
return; |
392 |
|
} |