From beae81621de52b14c5e4f91f17dfb3989dc99bec Mon Sep 17 00:00:00 2001 From: Sean Kirby Date: Tue, 26 Apr 2011 12:18:21 -0400 Subject: [PATCH] Added ability to run arbitrary commands on remote machines (useful for updating bundles!) --- lib/hydra/tasks.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/hydra/tasks.rb b/lib/hydra/tasks.rb index ed28637..0265bb6 100644 --- a/lib/hydra/tasks.rb +++ b/lib/hydra/tasks.rb @@ -243,8 +243,9 @@ module Hydra #:nodoc: include Open3 # Create a new hydra remote task with the given name. # The task will be named hydra:remote: - def initialize(name) + def initialize(name, command=nil) @name = name + @command = command yield self if block_given? @config = find_config_file if @config @@ -262,6 +263,7 @@ module Hydra #:nodoc: environment = config.fetch('environment') { 'test' } workers = config.fetch('workers') { [] } workers = workers.select{|w| w['type'] == 'ssh'} + @command = "RAILS_ENV=#{environment} rake #{@name}" unless @command $stdout.write "==== Hydra Running #{@name} ====\n" Thread.abort_on_exception = true @@ -270,7 +272,7 @@ module Hydra #:nodoc: workers.each do |worker| @listeners << Thread.new do begin - @results[worker] = if run_task(worker, environment) + @results[worker] = if run_command(worker, @command) "==== #{@name} passed on #{worker['connect']} ====\n" else "==== #{@name} failed on #{worker['connect']} ====\nPlease see above for more details.\n" @@ -286,13 +288,13 @@ module Hydra #:nodoc: end end - def run_task worker, environment + def run_command worker, command $stdout.write "==== Hydra Running #{@name} on #{worker['connect']} ====\n" ssh_opts = worker.fetch('ssh_opts') { '' } writer, reader, error = popen3("ssh -tt #{ssh_opts} #{worker['connect']} ") writer.write("cd #{worker['directory']}\n") writer.write "echo BEGIN HYDRA\n" - writer.write("RAILS_ENV=#{environment} rake #{@name}\n") + writer.write(command + "\r") writer.write "echo END HYDRA\n" writer.write("exit\n") writer.close