weave 1.0.1 → 1.0.2.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/weave.rb +51 -26
- data/lib/weave/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c11f2751ec38a419142cd0f20bfab5a12f42393
|
4
|
+
data.tar.gz: e078add354738f1f22b85c12c01817e83349ca02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d86352f8c23e2b51dd8f64ffbe91b5f5e8da46452442656b24dd07cec4e0ee5600958179f70685ef2244184424b5425b7ec064b7be7d0b69b0cc07eb7f2ea561
|
7
|
+
data.tar.gz: 824967f7cd66565084c8376899abd1379ef10a222e309603435f224f3edbfb0e692fb054ee5ae2c03d46e3e952ed2997947b67dad285c49469a0bfaba0857253
|
data/lib/weave.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "net/ssh"
|
2
2
|
require "thread"
|
3
|
+
require "timeout"
|
3
4
|
|
4
5
|
module Weave
|
5
6
|
DEFAULT_THREAD_POOL_SIZE = 10
|
@@ -143,47 +144,71 @@ module Weave
|
|
143
144
|
# command terminated via a signal or with a non-zero exit status. Otherwise (the default), these will
|
144
145
|
# cause a `Weave::Error` to be raised.
|
145
146
|
#
|
147
|
+
# The option `:timeout`, if provided, specifies the number of seconds to allow the command to execute
|
148
|
+
# before timing it out. If this happens, the output is unchanged (but in most cases, this will be an error
|
149
|
+
# as your process was killed by a signal from the pseudo-tty Weave allocates for it on the remote host).
|
150
|
+
# If the command is timed out, the result hash also has `:timed_out => true` (is is `false` otherwise).
|
151
|
+
#
|
146
152
|
# @param [Hash] options the output options
|
147
153
|
# @option options [Symbol] :output the output format
|
154
|
+
# @option options [Symbol] :continue_on_failure whether to raise an exception if the command exits with a
|
155
|
+
# non-zero exit status or because of a signal
|
156
|
+
# @option options[Symbol] :timeout if given, how many seconds to give the command before timing it out
|
148
157
|
def run(command, options = {})
|
149
158
|
options[:output] ||= :pretty
|
150
159
|
@connection ||= Net::SSH.start(@host, @user)
|
151
160
|
result = options[:output] == :capture ? { :stdout => "", :stderr => "" } : {}
|
161
|
+
result[:timed_out] = false
|
152
162
|
@connection.open_channel do |channel|
|
153
|
-
channel.
|
154
|
-
unless success
|
155
|
-
|
156
|
-
|
163
|
+
channel.request_pty do |ch, success|
|
164
|
+
raise Error, "Error requesting pty" unless success
|
165
|
+
ch.exec(command) do |_, succ|
|
166
|
+
unless succ
|
167
|
+
raise Error, "Could not run ssh command: #{command}"
|
168
|
+
end
|
157
169
|
|
158
|
-
|
159
|
-
|
160
|
-
|
170
|
+
ch.on_data do |_, data|
|
171
|
+
append_or_print_output(result, data, :stdout, options)
|
172
|
+
end
|
161
173
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
174
|
+
ch.on_extended_data do |_, type, data|
|
175
|
+
next unless type == 1
|
176
|
+
append_or_print_output(result, data, :stderr, options)
|
177
|
+
end
|
166
178
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
179
|
+
ch.on_request("exit-status") do |_, data|
|
180
|
+
code = data.read_long
|
181
|
+
unless code.zero? || options[:continue_on_failure]
|
182
|
+
raise Error, "[#{@host}] command finished with exit status #{code}: #{command}"
|
183
|
+
end
|
184
|
+
result[:exit_code] = code
|
171
185
|
end
|
172
|
-
result[:exit_code] = code
|
173
|
-
end
|
174
186
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
187
|
+
ch.on_request("exit-signal") do |_, data|
|
188
|
+
signal = data.read_long
|
189
|
+
unless options[:continue_on_failure]
|
190
|
+
signal_name = Signal.list.invert[signal]
|
191
|
+
signal_message = signal_name ? "#{signal} (#{signal_name})" : "#{signal}"
|
192
|
+
raise Error, "[#{@host}] command received signal #{signal_message}: #{command}"
|
193
|
+
end
|
194
|
+
result[:exit_signal] = signal
|
181
195
|
end
|
182
|
-
result[:exit_signal] = signal
|
183
196
|
end
|
184
197
|
end
|
185
198
|
end
|
186
|
-
|
199
|
+
if options[:timeout].nil?
|
200
|
+
@connection.loop(0.05)
|
201
|
+
else
|
202
|
+
begin
|
203
|
+
Timeout.timeout(options[:timeout]) do
|
204
|
+
@connection.loop(0.05)
|
205
|
+
end
|
206
|
+
rescue Timeout::Error
|
207
|
+
@connection.close
|
208
|
+
@connection = nil
|
209
|
+
result[:timed_out] = true
|
210
|
+
end
|
211
|
+
end
|
187
212
|
result
|
188
213
|
end
|
189
214
|
|
@@ -207,7 +232,7 @@ module Weave
|
|
207
232
|
|
208
233
|
# @private
|
209
234
|
def self.user_and_host(host_string)
|
210
|
-
user,
|
235
|
+
user, _, host = host_string.rpartition("@")
|
211
236
|
if [user, host].any? { |part| part.nil? || part.empty? }
|
212
237
|
raise "Bad hostname (needs to be of the form user@host): #{host_string}"
|
213
238
|
end
|
data/lib/weave/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Spare
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -116,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- - '
|
119
|
+
- - '>'
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
121
|
+
version: 1.3.1
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
124
|
rubygems_version: 2.0.3
|