has ssh => (is => 'ro', default => sub { {} });
sub handle_create {
- my ($self, $on) = @_;
- my ($kid_in, $kid_out, $kid_pid) = $self->_open($on);
+ my ($self, $on, %args) = @_;
+ my $log_level = $args{log_level}||'info';
+ my ($kid_in, $kid_out, $kid_pid) = $self->_open($on, $log_level);
$kid_in->print(io('maint/mk-fat |')->all, "__END__\n");
+ my $up = <$kid_out>;
+ die [ failure => "Garbled response from child: $up" ]
+ unless $up eq "UP\n";
my $connection = Tak::ConnectionService->new(
read_fh => $kid_out, write_fh => $kid_in,
listening_service => Tak::Router->new
}
sub _open {
- my ($self, $on) = @_;
+ my ($self, $on, @args) = @_;
unless ($on) {
- my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-')
+ my $kid_pid = IPC::Open2::open2(my $kid_out, my $kid_in, $^X, '-', '-', @args)
or die "Couldn't open2 child: $!";
return ($kid_in, $kid_out, $kid_pid);
}
my $ssh = $self->ssh->{$on} ||= Net::OpenSSH->new($on);
$ssh->error and
die "Couldn't establish ssh connection: ".$ssh->error;
- return $ssh->open2('perl','-');
+ return $ssh->open2('perl','-', $on, @args);
}
sub start_connection_request {
use JSON::PP qw(encode_json decode_json);
use IO::Handle;
use Scalar::Util qw(weaken);
+use Log::Contextual qw(:log);
use Moo;
has read_fh => (is => 'ro', required => 1);
sub read_message {
my ($self) = @_;
if (defined(my $line = readline($self->read_fh))) {
+ log_trace { "Received $line" };
if (my $unpacked = $self->_unpack_line($line)) {
return $unpacked;
}
);
return;
}
+ log_trace { "Sending: $json" };
$self->_raw_write_message($json);
}
package Tak::STDIOSetup;
-BEGIN { require MRO::Compat; }
-
+use Log::Contextual qw(:log);
+use Log::Contextual::SimpleLogger;
use Tak::ConnectionService;
use Tak::Router;
use Tak;
use strictures 1;
sub run {
- open my $stdin, '<&', \*STDIN;
- open my $stdout, '>&', \*STDOUT;
+ open my $stdin, '<&', \*STDIN or die "Duping stdin: $!";
+ open my $stdout, '>&', \*STDOUT or die "Duping stdout: $!";
# if we don't re-open them then 0 and 1 get re-used - which is not
# only potentially bloody confusing but results in warnings like:
# "Filehandle STDOUT reopened as STDIN only for input"
- close STDIN; open STDIN, '<', '/dev/null';
- close STDOUT; open STDOUT, '>', '/dev/null';
+ close STDIN or die "Closing stdin: $!";
+ open STDIN, '<', '/dev/null' or die "Re-opening stdin: $!";
+ close STDOUT or die "Closing stdout: $!";
+ open STDOUT, '>', '/dev/null' or die "Re-opening stdout: $!";
+ my ($host, $level) = @ARGV;
+ my $sig = '<'.join ':', $host, $$.'> ';
+ Log::Contextual::set_logger(
+ Log::Contextual::SimpleLogger->new({
+ levels_upto => $level,
+ coderef => sub { print STDERR $sig, @_; }
+ })
+ );
my $done;
my $connection = Tak::ConnectionService->new(
read_fh => $stdin, write_fh => $stdout,
if ($0 eq '-') {
$0 = 'tak-stdio-node';
}
+ log_debug { "Node starting" };
+ print $stdout "UP\n";
Tak->loop_until($done);
}
use Tak::Client::Router;
use Tak::Client::RemoteRouter;
use Tak::Router;
+use Log::Contextual qw(:log);
+use Log::Contextual::SimpleLogger;
use Moo;
has options => (is => 'ro', required => 1);
has env => (is => 'ro', required => 1);
+has log_level => (is => 'rw');
+
has stdin => (is => 'lazy');
has stdout => (is => 'lazy');
has stderr => (is => 'lazy');
shift->setup_logger;
}
-sub setup_logger { }
+sub setup_logger {
+ my ($self) = @_;
+ my @level_names = qw(fatal error warn info debug trace);
+ my $options = $self->options;
+ my $level = 2 + ($options->{verbose}||0) - ($options->{quiet}||0);
+ my $upto = $level_names[$level];
+ $self->log_level($upto);
+ Log::Contextual::set_logger(
+ Log::Contextual::SimpleLogger->new({
+ levels_upto => $upto,
+ coderef => sub { print STDERR '<local> ', @_ },
+ })
+ );
+}
sub _parse_options {
my ($self, $string, $argv) = @_;
sub _connection_to {
my ($self, $target) = @_;
- my @path = $self->local_client->do(connector => create => $target);
+ log_debug { "Connecting to ${target}" };
+ my @path = $self->local_client->do(
+ connector => create => $target, log_level => $self->log_level
+ );
my ($local, $remote) =
map $self->local_client->curry(connector => connection => @path => $_),
qw(local remote);
expose => { module_sender => [ 'remote', 'module_sender' ] }
);
$remote->do(module_loader => 'enable');
+ log_debug { "Setup connection to ${target}" };
Tak::Client::RemoteRouter->new(
%$remote, host => $target
);
#!/bin/sh
#if [ -e fatlib ]; then rm -r fatlib; fi
-#fatpack tree $(fatpack packlists-for strictures.pm Moo.pm JSON/PP.pm MRO/Compat.pm Class/C3.pm Algorithm/C3.pm)
+#fatpack tree $(fatpack packlists-for strictures.pm Moo.pm JSON/PP.pm MRO/Compat.pm Class/C3.pm Algorithm/C3.pm Log/Contextual.pm Data/Dumper/Concise.pm)
fatpack file
#rm -r fatlib
echo "use lib 'lib'; use Tak::STDIOSetup; Tak::STDIOSetup->run;"