Method: Cloudler.run

Defined in:
lib/cloudler.rb

.run(to_run = [:upload, :precommands, :gems, :command]) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cloudler.rb', line 24

def self.run to_run = [:upload, :precommands, :gems, :command]
	# Set some defaults
	@files ||= []
	@gems ||= []
	@precommands ||= []
	@path ||= 
		if @username == 'root'
			'/root/.cloudler'
		else
			"/home/#{@username}/.cloudler"
		end

	@hosts.each do |host|
		Net::SSH.start(host, @username, :password => @password) do |ssh|
			if to_run.member? :upload
				puts "Uploading files..."
				upload_files ssh	
				puts "Files uploaded."
			end

			if to_run.member? :precommands
				if @precommands.length > 0
					puts "Executing pre-commands"
					execute_precommands ssh
					puts "Pre-commands executed."
				end
			end

			if to_run.member? :gems
				if @gems.length > 0 
					puts "Installing gems..."
					install_gems ssh
					puts "Gems installed"
				end
			end

			if to_run.member? :command
				puts "Executing command..."
				execute_command ssh
				puts "Command finished."
			end
		end				
	end
end