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.27 by pjm2, Wed Mar 14 18:00:16 2001 UTC vs.
Revision 1.30 by pjm2, Thu Mar 15 09:44:08 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 = "/var/tmp/ihost.pid";
# 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 == 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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines