#!/usr/local/groundwork/perl/bin/perl -w -- # # Copyright 2007-2010 GroundWork Open Source, Inc. (GroundWork) # All rights reserved. This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 as published # by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this # program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, # Fifth Floor, Boston, MA 02110-1301, USA. use strict; use IO::Socket; my $host = $ARGV[0]; my $port = $ARGV[1]; my $socket; # GWMON-7407 my $socket_send_timeout = 60; print "\nConnecting to Foundation listener (Host:$host Port:$port):\n"; for (my $i = 0; $i < 20; ++$i) { $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM); if ($socket) { $socket->autoflush(); my $failed = 0; unless ( $socket->sockopt(SO_SNDTIMEO, pack('L!L!', $socket_send_timeout, 0)) ) { print "ERROR: failed to set send timeout on socket\n"; $failed = 1; } unless ($failed) { print " Listener is ready to accept data feeds ...\n"; unless ( $socket->print( '' ) ) { print "ERROR: failed writing to socket\n"; $failed = 1; } } unless ( close($socket) ) { print "ERROR: failed closing socket\n"; $failed = 1; } if ($failed) { print " Listener services are not yet available ...\n"; } else { print " Listener services are available.\n"; exit 0; } } else { print " Listener is not ready to accept data feeds ...\n"; sleep 15; } } print " Listener is not accepting calls. System might be still initializing.\n"; exit 1;