rudy 0.8.1 → 0.8.2
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.
- data/CHANGES.txt +21 -8
- data/README.rdoc +43 -1
- data/Rudyfile +28 -27
- data/bin/rudy +8 -15
- data/lib/rudy.rb +2 -2
- data/lib/rudy/cli/routines.rb +4 -20
- data/lib/rudy/config.rb +1 -0
- data/lib/rudy/config/objects.rb +29 -33
- data/lib/rudy/huxtable.rb +9 -1
- data/lib/rudy/routines.rb +113 -96
- data/lib/rudy/routines/helper.rb +3 -3
- data/lib/rudy/routines/helpers/dependshelper.rb +1 -1
- data/lib/rudy/routines/helpers/diskhelper.rb +3 -3
- data/lib/rudy/routines/helpers/scripthelper.rb +41 -39
- data/lib/rudy/routines/helpers/userhelper.rb +5 -5
- data/lib/rudy/routines/passthrough.rb +11 -11
- data/lib/rudy/routines/startup.rb +1 -1
- data/rudy.gemspec +4 -37
- metadata +5 -38
- data/examples/README.md +0 -10
- data/examples/debian-sinatra-passenger/commands.rb +0 -19
- data/examples/debian-sinatra-passenger/machines.rb +0 -32
- data/examples/debian-sinatra-passenger/routines.rb +0 -30
- data/examples/debian-sinatra-thin/commands.rb +0 -17
- data/examples/debian-sinatra-thin/machines.rb +0 -35
- data/examples/debian-sinatra-thin/routines.rb +0 -72
- data/lib/rudy/routines/helpers/scmhelper.rb +0 -39
- data/lib/rudy/routines/release.rb +0 -48
- data/lib/rudy/scm.rb +0 -75
- data/lib/rudy/scm/git.rb +0 -217
- data/lib/rudy/scm/svn.rb +0 -110
- data/test/01_mixins/10_hash_test.rb +0 -25
- data/test/10_config/00_setup_test.rb +0 -20
- data/test/10_config/30_machines_test.rb +0 -69
- data/test/15_scm/00_setup_test.rb +0 -20
- data/test/15_scm/20_git_test.rb +0 -61
- data/test/20_sdb/00_setup_test.rb +0 -16
- data/test/20_sdb/10_domains_test.rb +0 -115
- data/test/25_ec2/00_setup_test.rb +0 -29
- data/test/25_ec2/10_keypairs_test.rb +0 -41
- data/test/25_ec2/20_groups_test.rb +0 -131
- data/test/25_ec2/30_addresses_test.rb +0 -38
- data/test/25_ec2/40_volumes_test.rb +0 -49
- data/test/25_ec2/50_snapshots_test.rb +0 -74
- data/test/26_ec2_instances/00_setup_test.rb +0 -28
- data/test/26_ec2_instances/10_instances_test.rb +0 -83
- data/test/26_ec2_instances/50_images_test.rb +0 -13
- data/test/30_sdb_metadata/00_setup_test.rb +0 -21
- data/test/30_sdb_metadata/10_disks_test.rb +0 -109
- data/test/30_sdb_metadata/20_backups_test.rb +0 -102
- data/test/coverage.txt +0 -51
- 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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
Rudy::Utils.
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
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,
|
349
|
+
Annoy.pose_question(" Keep going?\a ", /yes|y|ya|sure|you bet!/i, STDOUT)
|
333
350
|
end
|
334
351
|
|
335
352
|
end
|
data/lib/rudy/routines/helper.rb
CHANGED
@@ -5,7 +5,7 @@ module Rudy
|
|
5
5
|
module HelperBase
|
6
6
|
include Rudy::Huxtable
|
7
7
|
|
8
|
-
def
|
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
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Rudy; module Routines;
|
4
4
|
module DiskHelper
|
5
|
-
include Rudy::Routines::HelperBase # TODO: use
|
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
|
-
|
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
|
-
|
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
|
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
|
-
@@
|
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(@@
|
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
|
-
|
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,
|
143
|
-
rbox.chmod(600,
|
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
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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(
|
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
|