rudy 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES.txt +21 -8
  2. data/README.rdoc +43 -1
  3. data/Rudyfile +28 -27
  4. data/bin/rudy +8 -15
  5. data/lib/rudy.rb +2 -2
  6. data/lib/rudy/cli/routines.rb +4 -20
  7. data/lib/rudy/config.rb +1 -0
  8. data/lib/rudy/config/objects.rb +29 -33
  9. data/lib/rudy/huxtable.rb +9 -1
  10. data/lib/rudy/routines.rb +113 -96
  11. data/lib/rudy/routines/helper.rb +3 -3
  12. data/lib/rudy/routines/helpers/dependshelper.rb +1 -1
  13. data/lib/rudy/routines/helpers/diskhelper.rb +3 -3
  14. data/lib/rudy/routines/helpers/scripthelper.rb +41 -39
  15. data/lib/rudy/routines/helpers/userhelper.rb +5 -5
  16. data/lib/rudy/routines/passthrough.rb +11 -11
  17. data/lib/rudy/routines/startup.rb +1 -1
  18. data/rudy.gemspec +4 -37
  19. metadata +5 -38
  20. data/examples/README.md +0 -10
  21. data/examples/debian-sinatra-passenger/commands.rb +0 -19
  22. data/examples/debian-sinatra-passenger/machines.rb +0 -32
  23. data/examples/debian-sinatra-passenger/routines.rb +0 -30
  24. data/examples/debian-sinatra-thin/commands.rb +0 -17
  25. data/examples/debian-sinatra-thin/machines.rb +0 -35
  26. data/examples/debian-sinatra-thin/routines.rb +0 -72
  27. data/lib/rudy/routines/helpers/scmhelper.rb +0 -39
  28. data/lib/rudy/routines/release.rb +0 -48
  29. data/lib/rudy/scm.rb +0 -75
  30. data/lib/rudy/scm/git.rb +0 -217
  31. data/lib/rudy/scm/svn.rb +0 -110
  32. data/test/01_mixins/10_hash_test.rb +0 -25
  33. data/test/10_config/00_setup_test.rb +0 -20
  34. data/test/10_config/30_machines_test.rb +0 -69
  35. data/test/15_scm/00_setup_test.rb +0 -20
  36. data/test/15_scm/20_git_test.rb +0 -61
  37. data/test/20_sdb/00_setup_test.rb +0 -16
  38. data/test/20_sdb/10_domains_test.rb +0 -115
  39. data/test/25_ec2/00_setup_test.rb +0 -29
  40. data/test/25_ec2/10_keypairs_test.rb +0 -41
  41. data/test/25_ec2/20_groups_test.rb +0 -131
  42. data/test/25_ec2/30_addresses_test.rb +0 -38
  43. data/test/25_ec2/40_volumes_test.rb +0 -49
  44. data/test/25_ec2/50_snapshots_test.rb +0 -74
  45. data/test/26_ec2_instances/00_setup_test.rb +0 -28
  46. data/test/26_ec2_instances/10_instances_test.rb +0 -83
  47. data/test/26_ec2_instances/50_images_test.rb +0 -13
  48. data/test/30_sdb_metadata/00_setup_test.rb +0 -21
  49. data/test/30_sdb_metadata/10_disks_test.rb +0 -109
  50. data/test/30_sdb_metadata/20_backups_test.rb +0 -102
  51. data/test/coverage.txt +0 -51
  52. data/test/helper.rb +0 -36
data/lib/rudy/huxtable.rb CHANGED
@@ -241,6 +241,7 @@ module Rudy
241
241
  # That's how Rudy knows the current group is defined.
242
242
  def known_machine_group?
243
243
  raise NoConfig unless @@config
244
+ return true if default_machine_group?
244
245
  raise NoMachinesConfig unless @@config.machines
245
246
  return false if !@@config && !@@global
246
247
  zon, env, rol = @@global.zone, @@global.environment, @@global.role
@@ -327,13 +328,20 @@ module Rudy
327
328
  def fetch_machine_param(parameter)
328
329
  raise "No parameter specified" unless parameter
329
330
  raise NoConfig unless @@config
330
- raise NoMachinesConfig unless @@config.machines
331
+ return if !@@config.machines && default_machine_group?
332
+ raise NoMachinesConfig if !@@config.machines
331
333
  raise NoGlobal unless @@global
332
334
  top_level = @@config.machines.find(parameter)
333
335
  mc = fetch_machine_config
334
336
  mc[parameter] || top_level || nil
335
337
  end
336
338
 
339
+ # Returns true if this is the default machine environment and role
340
+ def default_machine_group?
341
+ @@global.environment == @@config.defaults.environment &&
342
+ @@global.role == @@config.defaults.role
343
+ end
344
+
337
345
  def fetch_machine_config
338
346
  raise NoConfig unless @@config
339
347
  raise NoMachinesConfig unless @@config.machines
data/lib/rudy/routines.rb CHANGED
@@ -8,8 +8,11 @@ module Rudy
8
8
 
9
9
  class Base
10
10
  include Rudy::Huxtable
11
-
12
- def initialize(*args)
11
+
12
+ # * +cmdname+ The name of the command specified on the command line
13
+ # * +option+ An OpenStruct of named command line options
14
+ # * +argv+ An Array of command line argument
15
+ def initialize(cmdname, option, argv, *args)
13
16
  a, s, r = @@global.accesskey, @@global.secretkey, @@global.region
14
17
  @sdb = Rudy::AWS::SDB.new(a, s, r)
15
18
  @rinst = Rudy::AWS::EC2::Instances.new(a, s, r)
@@ -17,11 +20,12 @@ module Rudy
17
20
  @rkey = Rudy::AWS::EC2::KeyPairs.new(a, s, r)
18
21
  @rvol = Rudy::AWS::EC2::Volumes.new(a, s, r)
19
22
  @rsnap = Rudy::AWS::EC2::Snapshots.new(a, s, r)
23
+ @cmdname, @option, @argv = cmdname, option, argv
24
+ @option ||= OpenStruct.new
20
25
  init(*args)
21
26
  end
22
27
 
23
- def init
24
- end
28
+ def init; raise "Must override init"; end
25
29
 
26
30
  def execute
27
31
  raise "Override execute method"
@@ -39,6 +43,8 @@ module Rudy
39
43
  # machine between the disk routine and after blocks. The block receives
40
44
  # two argument: an instance of Rudy::Machine and one of Rye::Box.
41
45
  def generic_machine_runner(machine_action, routine=nil, skip_check=false, skip_header=false, &routine_action)
46
+ is_available= false
47
+
42
48
  if @@global.offline
43
49
  rmach = Rudy::Machines::Offline.new
44
50
  skip_check = true
@@ -74,14 +80,15 @@ module Rudy
74
80
  }
75
81
 
76
82
 
77
- lbox = Rye::Box.new('localhost')
83
+ lbox = Rye::Box.new('localhost', :info => false)
78
84
  sconf = fetch_script_config
79
85
 
80
86
  enjoy_every_sandwich {
81
87
  if Rudy::Routines::ScriptHelper.before_local?(routine) # before_local
82
88
  # Runs "before_local" scripts of routines config.
83
89
  puts task_separator("LOCAL SHELL")
84
- Rudy::Routines::ScriptHelper.before_local(routine, sconf, lbox)
90
+ lbox.cd Dir.pwd # Run local command block from current working directory
91
+ Rudy::Routines::ScriptHelper.before_local(routine, sconf, lbox, @option, @argv)
85
92
  end
86
93
  }
87
94
 
@@ -90,12 +97,13 @@ module Rudy
90
97
  # Runs "script_local" scripts of routines config.
91
98
  # NOTE: This is synonymous with before_local
92
99
  puts task_separator("LOCAL SHELL")
93
- Rudy::Routines::ScriptHelper.script_local(routine, sconf, lbox)
100
+ lbox.cd Dir.pwd # Run local command block from current working directory
101
+ Rudy::Routines::ScriptHelper.script_local(routine, sconf, lbox, @option, @argv)
94
102
  end
95
103
  }
96
104
 
97
105
  # Execute the action (create, list, destroy, restart)
98
- machines = enjoy_every_sandwich([]) { rmach.send(machine_action) }
106
+ machines = enjoy_every_sandwich([]) { rmach.send(machine_action) } || []
99
107
 
100
108
  machines.each do |machine|
101
109
  puts machine_separator(machine.name, machine.awsid) unless skip_header
@@ -129,80 +137,86 @@ module Rudy
129
137
  next # The short circuit
130
138
  end
131
139
 
132
- unless skip_check
133
- msg = preliminary_separator("Waiting for SSH daemon...")
134
- Rudy::Utils.waiter(2, 60, STDOUT, msg, 0) {
135
- Rudy::Utils.service_available?(machine.dns_public, 22)
140
+ if !skip_check && has_remote_task?(routine)
141
+ enjoy_every_sandwich {
142
+ msg = preliminary_separator("Waiting for SSH daemon...")
143
+ ret = Rudy::Utils.waiter(2, 1, STDOUT, msg, 0) {
144
+ Rudy::Utils.service_available?(machine.dns_public, 22)
145
+ }
146
+ is_available = ret
136
147
  }
137
148
  end
138
149
 
139
- # TODO: trap rbox errors. We could get an authentication error.
140
- opts = { :keys => root_keypairpath, :user => remote_user, :info => @@global.verbose > 0 }
141
- begin
142
- rbox = Rye::Box.new(machine.dns_public, opts)
143
- rbox.connect
144
- rescue Rye::NoHost => ex
145
- STDERR.puts "No host: #{ex.message}"
146
- exit 65
147
- end
150
+ if is_available
151
+ # TODO: trap rbox errors. We could get an authentication error.
152
+ opts = { :keys => root_keypairpath, :user => remote_user, :info => @@global.verbose > 0 }
153
+ begin
154
+ rbox = Rye::Box.new(machine.dns_public, opts)
155
+ Rudy::Utils.waiter(2, 10, STDOUT, nil, 0) { rbox.connect }
156
+ rescue Rye::NoHost => ex
157
+ STDERR.puts "No host: #{ex.message}"
158
+ exit 65
159
+ end
148
160
 
149
- unless skip_check
150
- # Set the hostname if specified in the machines config.
151
- # :rudy -> change to Rudy's machine name
152
- # :default -> leave the hostname as it is
153
- # Anything else other than nil -> change to that value
154
- # NOTE: This will set hostname every time a routine is
155
- # run so we may want to make this an explicit action.
161
+ unless skip_check
162
+ # Set the hostname if specified in the machines config.
163
+ # :rudy -> change to Rudy's machine name
164
+ # :default -> leave the hostname as it is
165
+ # Anything else other than nil -> change to that value
166
+ # NOTE: This will set hostname every time a routine is
167
+ # run so we may want to make this an explicit action.
168
+ enjoy_every_sandwich {
169
+ hn = current_machine_hostname || :rudy
170
+ if hn != :default
171
+ hn = machine.name if hn == :rudy
172
+ print preliminary_separator("Setting hostname to #{hn}... ")
173
+ rbox.hostname(hn)
174
+ puts "done"
175
+ end
176
+ }
177
+ end
178
+
179
+
180
+ ## NOTE: This prevents shutdown from doing its thing and prob
181
+ ## isn't necessary.
182
+ ##unless has_remote_task?(routine)
183
+ ## puts "[no remote tasks]"
184
+ ## next
185
+ ##end
186
+
156
187
  enjoy_every_sandwich {
157
- hn = current_machine_hostname || :rudy
158
- if hn != :default
159
- hn = machine.name if hn == :rudy
160
- print preliminary_separator("Setting hostame to #{hn}... ")
161
- rbox.hostname(hn)
162
- puts "done"
188
+ if Rudy::Routines::UserHelper.adduser?(routine) # adduser
189
+ puts task_separator("ADD USER")
190
+ Rudy::Routines::UserHelper.adduser(routine, machine, rbox)
163
191
  end
164
192
  }
165
- end
166
193
 
167
- ## NOTE: This prevents shutdown from doing its thing and prob
168
- ## isn't necessary.
169
- ##unless has_remote_task?(routine)
170
- ## puts "[no remote tasks]"
171
- ## next
172
- ##end
173
-
174
- enjoy_every_sandwich {
175
- if Rudy::Routines::UserHelper.adduser?(routine) # adduser
176
- puts task_separator("ADD USER")
177
- Rudy::Routines::UserHelper.adduser(routine, machine, rbox)
178
- end
179
- }
180
-
181
- enjoy_every_sandwich {
182
- if Rudy::Routines::UserHelper.authorize?(routine) # authorize
183
- puts task_separator("AUTHORIZE USER")
184
- Rudy::Routines::UserHelper.authorize(routine, machine, rbox)
185
- end
186
- }
194
+ enjoy_every_sandwich {
195
+ if Rudy::Routines::UserHelper.authorize?(routine) # authorize
196
+ puts task_separator("AUTHORIZE USER")
197
+ Rudy::Routines::UserHelper.authorize(routine, machine, rbox)
198
+ end
199
+ }
187
200
 
188
- enjoy_every_sandwich {
189
- if Rudy::Routines::ScriptHelper.before?(routine) # before
190
- puts task_separator("REMOTE SHELL")
191
- Rudy::Routines::ScriptHelper.before(routine, sconf, machine, rbox)
192
- end
193
- }
201
+ enjoy_every_sandwich {
202
+ if Rudy::Routines::ScriptHelper.before?(routine) # before
203
+ puts task_separator("REMOTE SHELL")
204
+ Rudy::Routines::ScriptHelper.before(routine, sconf, machine, rbox, @option, @argv)
205
+ end
206
+ }
194
207
 
195
- enjoy_every_sandwich {
196
- if Rudy::Routines::DiskHelper.disks?(routine) # disk
197
- puts task_separator("DISKS")
198
- if rbox.ostype == "sunos"
199
- puts "Sorry, Solaris disks are not supported yet!"
200
- else
201
- Rudy::Routines::DiskHelper.execute(routine, machine, rbox)
202
- end
203
- end
204
- }
208
+ enjoy_every_sandwich {
209
+ if Rudy::Routines::DiskHelper.disks?(routine) # disk
210
+ puts task_separator("DISKS")
211
+ if rbox.ostype == "sunos"
212
+ puts "Sorry, Solaris disks are not supported yet!"
213
+ else
214
+ Rudy::Routines::DiskHelper.execute(routine, machine, rbox)
215
+ end
216
+ end
217
+ }
205
218
 
219
+ end
206
220
 
207
221
  enjoy_every_sandwich {
208
222
  # Startup, shutdown, release, deploy, etc...
@@ -210,37 +224,40 @@ module Rudy
210
224
  }
211
225
 
212
226
 
213
- # The "after" blocks are synonymous with "script" blocks.
214
- # For some routines, like startup, it makes sense to an
215
- # "after" block b/c "script" is ambiguous. In generic
216
- # routines, there is no concept of before or after. The
217
- # definition is the entire routine so we use "script".
218
- # NOTE: If both after and script are supplied they will
219
- # both be executed.
220
- enjoy_every_sandwich {
221
- if Rudy::Routines::ScriptHelper.script?(routine) # script
222
- puts task_separator("REMOTE SHELL")
223
- # Runs "after" scripts of routines config
224
- Rudy::Routines::ScriptHelper.script(routine, sconf, machine, rbox)
225
- end
226
- }
227
+ if is_available
228
+ # The "after" blocks are synonymous with "script" blocks.
229
+ # For some routines, like startup, it makes sense to an
230
+ # "after" block b/c "script" is ambiguous. In generic
231
+ # routines, there is no concept of before or after. The
232
+ # definition is the entire routine so we use "script".
233
+ # NOTE: If both after and script are supplied they will
234
+ # both be executed.
235
+ enjoy_every_sandwich {
236
+ if Rudy::Routines::ScriptHelper.script?(routine) # script
237
+ puts task_separator("REMOTE SHELL")
238
+ # Runs "after" scripts of routines config
239
+ Rudy::Routines::ScriptHelper.script(routine, sconf, machine, rbox, @option, @argv)
240
+ end
241
+ }
227
242
 
228
- enjoy_every_sandwich {
229
- if Rudy::Routines::ScriptHelper.after?(routine) # after
230
- puts task_separator("REMOTE SHELL")
231
- # Runs "after" scripts of routines config
232
- Rudy::Routines::ScriptHelper.after(routine, sconf, machine, rbox)
233
- end
234
- }
243
+ enjoy_every_sandwich {
244
+ if Rudy::Routines::ScriptHelper.after?(routine) # after
245
+ puts task_separator("REMOTE SHELL")
246
+ # Runs "after" scripts of routines config
247
+ Rudy::Routines::ScriptHelper.after(routine, sconf, machine, rbox, @option, @argv)
248
+ end
249
+ }
235
250
 
236
- rbox.disconnect
251
+ rbox.disconnect
252
+ end
237
253
  end
238
-
254
+
239
255
  enjoy_every_sandwich {
240
256
  if Rudy::Routines::ScriptHelper.after_local?(routine) # after_local
241
257
  puts task_separator("LOCAL SHELL")
258
+ lbox.cd Dir.pwd # Run local command block from current working directory
242
259
  # Runs "after_local" scripts of routines config
243
- Rudy::Routines::ScriptHelper.after_local(routine, sconf, lbox)
260
+ Rudy::Routines::ScriptHelper.after_local(routine, sconf, lbox, @option, @argv)
244
261
  end
245
262
  }
246
263
 
@@ -329,7 +346,7 @@ module Rudy
329
346
  end
330
347
 
331
348
  def keep_going?
332
- Annoy.pose_question(" Keep going?\a ", /yes|y|ya|sure|you bet!/i, STDERR)
349
+ Annoy.pose_question(" Keep going?\a ", /yes|y|ya|sure|you bet!/i, STDOUT)
333
350
  end
334
351
 
335
352
  end
@@ -5,7 +5,7 @@ module Rudy
5
5
  module HelperBase
6
6
  include Rudy::Huxtable
7
7
 
8
- def execute_rbox_command(ret=nil, &command)
8
+ def trap_rbox_errors(ret=nil, &command)
9
9
  begin
10
10
  ret = command.call if command
11
11
  return unless ret.is_a?(Rye::Rap)
@@ -31,11 +31,11 @@ module Rudy
31
31
  end
32
32
 
33
33
  # Returns a formatted string for printing command info
34
- def command_separator(cmd, user)
34
+ def command_separator(cmd, user, host)
35
35
  cmd ||= ""
36
36
  cmd, user = cmd.to_s, user.to_s
37
37
  prompt = user == "root" ? "#" : "$"
38
- ("%s%s%s %s" % [$/, user, prompt, cmd.bright])
38
+ ("%s%s@%s%s %s" % [$/, user, host, prompt, cmd.bright])
39
39
  end
40
40
 
41
41
  private
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rudy; module Routines;
3
3
  module DependsHelper
4
- include Rudy::Routines::HelperBase # TODO: use execute_rbox_command
4
+ include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
5
5
  extend self
6
6
 
7
7
  def has_depends?(timing, routine)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Rudy; module Routines;
4
4
  module DiskHelper
5
- include Rudy::Routines::HelperBase # TODO: use execute_rbox_command
5
+ include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
6
6
  extend self
7
7
 
8
8
  def disks?(routine)
@@ -271,7 +271,7 @@ module Rudy; module Routines;
271
271
 
272
272
  if disk.mounted?
273
273
  print "Unmounting #{disk.path}..."
274
- execute_rbox_command { @rbox.umount(disk.path) }
274
+ trap_rbox_errors { @rbox.umount(disk.path) }
275
275
  puts " done"
276
276
  sleep 0.5
277
277
  end
@@ -307,7 +307,7 @@ module Rudy; module Routines;
307
307
 
308
308
  if disk.mounted?
309
309
  print "Unmounting #{disk.path}..."
310
- execute_rbox_command { @rbox.umount(disk.path) }
310
+ trap_rbox_errors { @rbox.umount(disk.path) }
311
311
  puts " done"
312
312
  sleep 0.5
313
313
  end
@@ -5,16 +5,16 @@ module Rudy; module Routines;
5
5
  # TODO: Rename to ShellHelper
6
6
  #++
7
7
  module ScriptHelper
8
- include Rudy::Routines::HelperBase # TODO: use execute_rbox_command
8
+ include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
9
9
  extend self
10
10
 
11
11
  @@script_types = [:after, :before, :after_local, :before_local, :script, :script_local]
12
- @@script_config_file = "rudy-config.yml"
12
+ @@script_config_file_name = "rudy-config.yml"
13
13
 
14
14
  # TODO: refactor using this_method
15
15
 
16
- def before_local(routine, sconf, rbox)
17
- execute_command(:before_local, routine, sconf, 'localhost', rbox)
16
+ def before_local(routine, sconf, rbox, option=nil, argv=nil)
17
+ execute_command(:before_local, routine, sconf, 'localhost', rbox, option, argv)
18
18
  end
19
19
  def before_local?(routine)
20
20
  # before_local generally doesn't take a user name like the remote
@@ -24,8 +24,8 @@ module Rudy; module Routines;
24
24
  } if routine[:before_local].is_a?(Proc)
25
25
  execute_command?(:before_local, routine)
26
26
  end
27
- def script_local(routine, sconf, rbox)
28
- execute_command(:script_local, routine, sconf, 'localhost', rbox)
27
+ def script_local(routine, sconf, rbox, option=nil, argv=nil)
28
+ execute_command(:script_local, routine, sconf, 'localhost', rbox, option, argv)
29
29
  end
30
30
  def script_local?(routine)
31
31
  # before_local generally doesn't take a user name like the remote
@@ -36,8 +36,8 @@ module Rudy; module Routines;
36
36
  execute_command?(:script_local, routine)
37
37
  end
38
38
 
39
- def after_local(routine, sconf, rbox)
40
- execute_command(:after_local, routine, sconf, 'localhost', rbox)
39
+ def after_local(routine, sconf, rbox, option=nil, argv=nil)
40
+ execute_command(:after_local, routine, sconf, 'localhost', rbox, option, argv)
41
41
  end
42
42
  def after_local?(routine)
43
43
  routine[:after_local] = { # See before_local note
@@ -46,21 +46,21 @@ module Rudy; module Routines;
46
46
  execute_command?(:after_local, routine)
47
47
  end
48
48
 
49
- def before(routine, sconf, machine, rbox)
49
+ def before(routine, sconf, machine, rbox, option=nil, argv=nil)
50
50
  raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
51
- execute_command(:before, routine, sconf, machine.name, rbox)
51
+ execute_command(:before, routine, sconf, machine.name, rbox, option, argv)
52
52
  end
53
53
  def before?(routine); execute_command?(:before, routine); end
54
54
 
55
- def after(routine, sconf, machine, rbox)
55
+ def after(routine, sconf, machine, rbox, option=nil, argv=nil)
56
56
  raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
57
- execute_command(:after, routine, sconf, machine.name, rbox)
57
+ execute_command(:after, routine, sconf, machine.name, rbox, option, argv)
58
58
  end
59
59
  def after?(routine); execute_command?(:after, routine); end
60
60
 
61
- def script(routine, sconf, machine, rbox)
61
+ def script(routine, sconf, machine, rbox, option=nil, argv=nil)
62
62
  raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
63
- execute_command(:script, routine, sconf, machine.name, rbox)
63
+ execute_command(:script, routine, sconf, machine.name, rbox, option, argv)
64
64
  end
65
65
  def script?(routine); execute_command?(:script, routine); end
66
66
 
@@ -95,12 +95,16 @@ module Rudy; module Routines;
95
95
  # * +sconf+ is a config hash from machines config (ignored if nil)
96
96
  # * +hostname+ machine hostname that we're working on
97
97
  # * +rbox+ a Rye::Box instance for the machine we're working on
98
- def execute_command(timing, routine, sconf, hostname, rbox)
98
+ def execute_command(timing, routine, sconf, hostname, rbox, option=nil, argv=nil)
99
99
  raise "ScriptHelper: Not a Rye::Box" unless rbox.is_a?(Rye::Box)
100
100
  raise "ScriptHelper: #{timing}?" unless @@script_types.member?(timing)
101
101
 
102
+ # The config file that gets created on each remote machine
103
+ # will be created in the user's home directory.
104
+ script_config_remote_path = File.join(rbox.getenv['HOME'], @@script_config_file_name)
105
+
102
106
  if sconf && !sconf.empty?
103
- tf = Tempfile.new(@@script_config_file)
107
+ tf = Tempfile.new(@@script_config_file_name)
104
108
  Rudy::Utils.write_to_file(tf.path, sconf.to_hash.to_yaml, 'w')
105
109
  end
106
110
 
@@ -131,7 +135,7 @@ module Rudy; module Routines;
131
135
  next
132
136
  end
133
137
 
134
- execute_rbox_command {
138
+ trap_rbox_errors {
135
139
  # We need to create the config file for every script,
136
140
  # b/c the user may change and it would not be accessible.
137
141
  # We turn off safe mode so we can write the config file via SSH.
@@ -139,30 +143,35 @@ module Rudy; module Routines;
139
143
  # TODO: Replace with rbox.upload. Make it safe again!
140
144
  conf_str = StringIO.new
141
145
  conf_str.puts sconf.to_hash.to_yaml
142
- rbox.upload(conf_str, @@script_config_file)
143
- rbox.chmod(600, @@script_config_file)
146
+ rbox.upload(conf_str, script_config_remote_path)
147
+ rbox.chmod(600, script_config_remote_path)
144
148
  }
145
149
 
146
150
  begin
147
- # We define hooks so we can call the script block as a batch.
148
- # We intentionally set and unset the hooks so the other commands
149
- # (config file copy) don't get printed.
150
- #
151
- # This block gets called for every command method call.
152
- rbox.pre_command_hook do |cmd, args, user|
153
- puts command_separator(rbox.preview_command(cmd, args), user)
151
+ # We define hooks so we can still print each command and its output
152
+ # when running the command blocks. NOTE: We only print this in
153
+ # verbosity mode. We intentionally set and unset the hooks
154
+ # so the other commands (config file copy) don't get printed.
155
+ if @@global.verbose > 0
156
+ # This block gets called for every command method call.
157
+ rbox.pre_command_hook do |cmd, args, user, host|
158
+ puts command_separator(rbox.preview_command(cmd, args), user, host)
159
+ end
154
160
  end
155
- # And this one gets called after each command method call.
156
- rbox.post_command_hook do |ret|
157
- puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
158
- print_response(ret)
161
+ if @@global.verbose > 1
162
+ # And this one gets called after each command method call.
163
+ rbox.post_command_hook do |ret|
164
+ puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
165
+ print_response(ret)
166
+ end
159
167
  end
160
168
 
161
169
  ### EXECUTE THE COMMANDS BLOCK
162
- rbox.batch(&proc)
170
+ rbox.batch(option, argv, &proc)
163
171
 
164
172
  rbox.pre_command_hook = nil
165
173
  rbox.post_command_hook = nil
174
+
166
175
  rescue Rye::CommandError => ex
167
176
  print_response(ex)
168
177
  exit 12 unless keep_going?
@@ -172,15 +181,8 @@ module Rudy; module Routines;
172
181
  exit 12 unless keep_going?
173
182
  end
174
183
 
175
- # I was gettings errors about script_config_file not existing. There
176
- # might be a race condition when the rm command is called too quickly.
177
- # It's also quite possible I'm off my rocker!
178
- ## NOTE: I believe this was an issue with Rye. I fixed it when I was
179
- ## noticing the same error in another place. It hasn't repeated.
180
- ## sleep 0.1
181
-
182
184
  rbox.cd # reset to home dir
183
- rbox.rudy_tmp_rm(@@script_config_file)
185
+ rbox.rudy_tmp_rm(:f, script_config_remote_path) # -f to ignore errors
184
186
  end
185
187
 
186
188
  # Return the borrowed rbox instance to the user it was provided with