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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/runsible.rb +24 -23
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f31a8f06a0427b8f580a9240bc5698bc87e1b439
4
- data.tar.gz: bf3daedd7b2e648992ced1ea3ec8140f83e9f30c
3
+ metadata.gz: 992cc2b427ff134560b9c8439424ab133f3f3087
4
+ data.tar.gz: 386a88d858b494970ae9b1eb05fc5980a57c68ef
5
5
  SHA512:
6
- metadata.gz: 3c43fd82babf3dd5630fa2d1e69b82ff141a33ac23781b670a51d50e893e5313f8ad45305de6f9cd779176e720cf047e9c25866b8b66e59a5eebd6e79665b230
7
- data.tar.gz: 539a72b37cab94eba245b16fdd5d67bbd31ade5cecadd84cd10f34a5457a29b3a3eca3b4085c1ec5c8b3f865fef52cd515ace50f45e5ee92a27cd6e455617823
6
+ metadata.gz: fd5abe43d8ad3bcdf2f8ceb928a94043d573ae9733680124afb503dfc2827ffe798a9c399970520155adf98b7915b6ab0dac6ebf23b2fc2342b58fb963f53268
7
+ data.tar.gz: a5ccfbf8a493274aabaa9ee9f7cb0c495543660a533f6c489190444a1dee44aef0b328864af6e3a6c78ddc1735fb60df16cfd5c35e5955cf563ab1dec23efa13
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3.1
1
+ 0.1.4.1
@@ -1,14 +1,7 @@
1
1
  require 'yaml'
2
- require 'slop'
3
- require 'pony'
4
- require 'net/ssh'
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
- SSH_CNX_TIMEOUT = 10
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.warn e
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", e.to_s)
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
- exit_code == 0 or raise(CommandFailure, "[exit #{exit_code}] #{cmd}")
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
- yield if block_given?
260
+ val = block_given? ? yield : true
261
261
  self.warn self.end_banner(msg)
262
+ val
262
263
  end
263
264
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runsible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.1
4
+ version: 0.1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull