App-PersistentSSH

 view release on metacpan or  search on metacpan

lib/App/PersistentSSH.pm  view on Meta::CPAN

	my ( $self, $kernel, $output ) = @_[OBJECT, KERNEL, ARG0];
	$self->logger->debug("scutil err: $output");
};

event scutil_stdout => sub {
	my ( $self, $kernel, $output ) = @_[OBJECT, KERNEL, ARG0];

	if ( $output =~ m{^\s*changed key \[\d+\] = State:/Network/Global/IPv4} ) {
		$kernel->yield("network_changed");
	} elsif ( $output !~ m{^\s*notification callback} ) {
		$self->logger->debug("scutil out: $output");
	}
};

sub run {
	POE::Kernel->run;
}

__PACKAGE__

__END__

=pod

=head1 NAME

App::PersistentSSH - Kick an F<ssh> control master around on OSX using
F<scutil>

=head1 SYNOPSIS

	% persisshtent --host your.host.com

=head1 DESCRIPTION

This POE component will keep an SSH control master alive, depending on network status.

It uses the OSX command line tool F<scutil> to get notification on changes to
the C<State:/Network/Global/IPv4> configuration key. Whenever this key is changed
C<scutil -r> will be used to check if the specified host is directly reachable
(without creating a connection using e.g. PPP), and if so spawn F<ssh>.

If the host is not reachable, F<ssh> is stopped.

=head1 CONFIGURATION

Add something alongs the lines of

	Host *
		ControlPath /tmp/%r@%h:%p

to your F<ssh_config>, in order to configure the path that the F<ssh> control
master will bind on. C<ControlMaster auto> is not needed.

The advantage over C<ControlMaster auto> is that if you close your initial ssh,
which is the control master under C<auto> all subsequently made connections
will also close. By keeping a daemonized, managed instance of C<ssh> this
problem is avoided.


Use C<ssh -v yourhost> to verify that the connection really is going through
the control master.

You can create a F<launchd> service for this using
L<http://lingon.sourceforge.net/>. I use:

	<key>Disabled</key>
	<false/>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>pasta ssh</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/bin/perl</string>
		<string>/Users/nothingmuch/Perl/App-PersistentSSH/bin/persisshtent</string>
		<string>--verbose</string>
		<string>--host</string>
		<string>pasta.woobling.org</string>
	</array>

=head1 ATTRIBUTES

=over 4

=item host

The host to connect to. Must be a valid ipaddress/hostname, not just an ssh
config host entry.

=item ssh_verbose

Pass C<-v> to ssh.

=item ssh_opts

Additional options for ssh, useful for tunnelling etc.

=back

=head1 METHODS

=over 4

=item new

=item new_with_options

Spawn the POE component.

C<new_with_options> comes from L<MooseX::Getopt>.

=item run

Calls L<POE::Kernel/run>.

=back

=head1 VERSION CONTROL

This module is maintained using Darcs. You can get the latest version from



( run in 0.544 second using v1.01-cache-2.11-cpan-39bf76dae61 )