Hi All,
My task: creating an internal proxy server based on OpenSSH persistent
connection.
Net::OpenSSH
for that I have create a module: persistentSSH which has the following
method:
the method wakeup calls _connect_test method that tries to wakeup all
listed server found in $self->{'servers'}
(list of hashref with host, port, name....).
Method works as I have tested it when create an object using my module and
call $ps->wakeup();
Net::Server
Problem starts when I am wrapping the method call using Net::Server module.
I have override pre_loop_hook creating the persistentSSH object as self
property - server does forks therefore it should have 1 connection per
server for all the child processes - maybe this is my problem
I then override process_http_request method readind the QueryString and
accept cmd=wakeup
that will call $self->{'_persistentSSH'}->wakeup
When starting the server - all is OK, but when I try to call
http://localhost:8001/?cmd=wakeup
I noticed soon when _connect_test starts calling
$host_ref->{'ssh_con'}->check_master
i receive immediately general error 800 from the server - I have problem
debugging the issue
Can anyone help? make me understand what is my problem?
I noticed when doing a simple check if ssh connection is connected by
checking printing Dumper of the object - object exists (as far as Dumper
shows)
On Net::Server I added the log_level => 4 (to increase the log level to
verbose) - but no errors are found in the log :(
Regards
Chanan
# overrode post_configure
sub pre_loop_hook
{
my ($self) = @_;
# init _persistenConnection
$self->{'_persistentConnection'} = system::persistentSSH->new();
unless ($self->{'_persistentConnection'})
{
$self->log(1, "error: failed initializing
system::persistentConnection class object");
exit 1;
}
return $self->SUPER::pre_loop_hook(@_);
}
sub wakeup
{
my ($self, $params) = @_;
return $self->_connect_test();
}
# sub will start persisstant SSH connection
sub _connect_test
{
my ($self, $params) = @_;
# loop all servers
my $res = 1;
foreach my $host_ref (@{$self->{'servers'}})
{
# check params for specfic host
next if ($params && $params->{'host'} ne $host_ref->{'host'});
unless ($host_ref->{'ssh_con'} &&
$host_ref->{'ssh_con'}->check_master)
{
# try to establish connection
foreach (1..3)
{
# connect via SSH
my $port = $host_ref->{'port'} ? $host_ref->{'port'} : '22';
$host_ref->{'ssh_con'} = Net::OpenSSH->new (
"$host_ref->{'user'}\@$host_ref->{'host'}",
( 'password' => $host_ref->{'password'},
'port' => $port
)
);
last if ( $host_ref->{'ssh_con'} &&
$host_ref->{'ssh_con'}->check_master );
}
# check connection established
unless ($host_ref->{'ssh_con'} &&
$host_ref->{'ssh_con'}->check_master)
{
my $err = $host_ref->{'ssh_con'}->error;
$self->_error("failed to establish SSH connection to
$host_ref->{name}($host_ref->{host}), $err");
}
else
{
$self->_log("connection established to
$host_ref->{name}($host_ref->{host})"),
}
}
}
return $res;
}
--
===================
---- Chanan Berler ----
===================
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl