diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index 2eda5c8..c186208 100644 --- a/lib/hydra/master.rb +++ b/lib/hydra/master.rb @@ -172,7 +172,7 @@ module Hydra #:nodoc: trace "Booting SSH worker" trace command - ssh = Hydra::SSH.new("#{sync.ssh_opts} #{sync.connect}", sync.remote_dir, command) + ssh = Hydra::SSH.new("#{sync.ssh_opts} #{sync.connect}", sync.remote_dir, command, worker['timeout']) return { :io => ssh, :idle => false, :type => :ssh, :connect => sync.connect } else false diff --git a/lib/hydra/messaging_io.rb b/lib/hydra/messaging_io.rb index da8764f..1cab329 100644 --- a/lib/hydra/messaging_io.rb +++ b/lib/hydra/messaging_io.rb @@ -11,7 +11,10 @@ module Hydra #:nodoc: while true begin raise IOError unless @reader - message = @reader.gets + if !@timeout || (result = Kernel.select([@reader], [], [], @timeout)) + message = @reader.gets + end + return Message.build(:class => Hydra::Messages::Master::Shutdown) if result == nil return nil unless message return Message.build(eval(message.chomp)) rescue SyntaxError, NameError diff --git a/lib/hydra/pipe.rb b/lib/hydra/pipe.rb index a53f106..7aaf631 100644 --- a/lib/hydra/pipe.rb +++ b/lib/hydra/pipe.rb @@ -31,9 +31,10 @@ module Hydra #:nodoc: class Pipe include Hydra::MessagingIO # Creates a new uninitialized pipe pair. - def initialize + def initialize(timeout = nil) @child_read, @parent_write = IO.pipe @parent_read, @child_write = IO.pipe + @timeout = timeout end # Identify this side of the pipe as the child. diff --git a/lib/hydra/ssh.rb b/lib/hydra/ssh.rb index ef6e740..3aed952 100644 --- a/lib/hydra/ssh.rb +++ b/lib/hydra/ssh.rb @@ -25,7 +25,8 @@ module Hydra #:nodoc: # Hydra::SSH.new('-p 3022 user@server.com', '/home/user/Desktop', 'ls -l') # To connect to server.com as user on port 3022, then CD to their desktop, then # list all the files. - def initialize(connection_options, directory, command) + def initialize(connection_options, directory, command, timeout = nil) + @timeout = timeout @writer, @reader, @error = popen3(%{ssh -tt #{connection_options} 'mkdir -p #{directory} && cd #{directory} && #{command}'}) end end