runsible 0.1.3.1 → 0.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/runsible.rb +24 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 992cc2b427ff134560b9c8439424ab133f3f3087
|
4
|
+
data.tar.gz: 386a88d858b494970ae9b1eb05fc5980a57c68ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5abe43d8ad3bcdf2f8ceb928a94043d573ae9733680124afb503dfc2827ffe798a9c399970520155adf98b7915b6ab0dac6ebf23b2fc2342b58fb963f53268
|
7
|
+
data.tar.gz: a5ccfbf8a493274aabaa9ee9f7cb0c495543660a533f6c489190444a1dee44aef0b328864af6e3a6c78ddc1735fb60df16cfd5c35e5955cf563ab1dec23efa13
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4.1
|
data/lib/runsible.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# for nonzero exit status of a remote command
|
7
|
-
class CommandFailure < RuntimeError
|
8
|
-
def to_s(*args)
|
9
|
-
"#{self.class}: #{super(*args)}"
|
10
|
-
end
|
11
|
-
end
|
2
|
+
autoload :Net, 'net/ssh'
|
3
|
+
autoload :Pony, 'pony'
|
4
|
+
autoload :Slop, 'slop'
|
12
5
|
|
13
6
|
# - this module is deliberately written without private state
|
14
7
|
# - it is meant to be used in the helper style
|
@@ -19,7 +12,7 @@ end
|
|
19
12
|
#
|
20
13
|
module Runsible
|
21
14
|
class Error < RuntimeError; end
|
22
|
-
|
15
|
+
class CommandFailure < Runsible::Error; end # nonzero exit
|
23
16
|
|
24
17
|
SETTINGS = {
|
25
18
|
user: ENV['USER'],
|
@@ -28,11 +21,16 @@ module Runsible
|
|
28
21
|
retries: 0,
|
29
22
|
vars: [],
|
30
23
|
}
|
24
|
+
SSH_CNX_TIMEOUT = 10
|
31
25
|
|
32
26
|
#
|
33
27
|
# Utility stuff
|
34
28
|
#
|
35
29
|
|
30
|
+
def self.excp(excp)
|
31
|
+
"#{excp.class}: #{excp.message}"
|
32
|
+
end
|
33
|
+
|
36
34
|
def self.default_settings
|
37
35
|
hsh = {}
|
38
36
|
SETTINGS.each { |sym, v|
|
@@ -45,13 +43,6 @@ module Runsible
|
|
45
43
|
File.read(File.join(__dir__, '..', 'VERSION'))
|
46
44
|
end
|
47
45
|
|
48
|
-
def self.usage(opts, msg=nil)
|
49
|
-
puts opts
|
50
|
-
puts
|
51
|
-
puts msg if msg
|
52
|
-
exit 1
|
53
|
-
end
|
54
|
-
|
55
46
|
def self.alert(topic, message, settings)
|
56
47
|
backend = settings['alerts'] && settings['alerts']['backend']
|
57
48
|
case backend
|
@@ -126,11 +117,18 @@ module Runsible
|
|
126
117
|
begin
|
127
118
|
yaml = YAML.load_file(yaml_filename)
|
128
119
|
rescue RuntimeError => e
|
129
|
-
Runsible.usage(opts, "could not load yaml_file\n#{e}")
|
120
|
+
Runsible.usage(opts, "could not load yaml_file\n#{self.excp(e)}")
|
130
121
|
end
|
131
122
|
yaml
|
132
123
|
end
|
133
124
|
|
125
|
+
def self.usage(opts, msg=nil)
|
126
|
+
puts opts
|
127
|
+
puts
|
128
|
+
puts msg if msg
|
129
|
+
exit 1
|
130
|
+
end
|
131
|
+
|
134
132
|
#
|
135
133
|
# Library stuff
|
136
134
|
#
|
@@ -164,10 +162,11 @@ module Runsible
|
|
164
162
|
begin
|
165
163
|
self.exec_retry(ssh, cmd, retries)
|
166
164
|
rescue CommandFailure, Net::SSH::Exception => e
|
167
|
-
self.
|
165
|
+
excp = self.excp(e)
|
166
|
+
self.warn excp
|
168
167
|
msg = "#{retries} retries exhausted; on_failure: #{on_failure}"
|
169
168
|
self.warn msg
|
170
|
-
self.alert(settings['email'], "retries exhausted",
|
169
|
+
self.alert(settings['email'], "retries exhausted", excp)
|
171
170
|
|
172
171
|
case on_failure
|
173
172
|
when 'continue'
|
@@ -227,7 +226,8 @@ module Runsible
|
|
227
226
|
end
|
228
227
|
end
|
229
228
|
ssh.loop # nothing actually executes until this call
|
230
|
-
|
229
|
+
raise(CommandFailure, "[exit #{exit_code}] #{cmd}") unless exit_code == 0
|
230
|
+
true
|
231
231
|
end
|
232
232
|
|
233
233
|
|
@@ -257,7 +257,8 @@ module Runsible
|
|
257
257
|
|
258
258
|
def self.banner_wrap(msg)
|
259
259
|
self.warn self.begin_banner(msg)
|
260
|
-
|
260
|
+
val = block_given? ? yield : true
|
261
261
|
self.warn self.end_banner(msg)
|
262
|
+
val
|
262
263
|
end
|
263
264
|
end
|